欢迎来到天天文库
浏览记录
ID:18203035
大小:70.00 KB
页数:5页
时间:2018-09-15
《棋盘覆盖和整数规划问题》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、《算法分析与设计》实验报告实验序号:实验4实验项目名称:棋盘覆盖和整数规划学 号姓 名专业、班实验地点指导教师时间一、实验目的及要求1、编程实现棋盘覆盖问题:Any2n´2n defectivechessboardcanbecoveredwith(2n´2n -1)/3triominoes. 2、编程实现整数划分问题:将正整数n表示成一系列正整数之和:n=n1+n2+…+nk,其中n1≥n2≥…≥nk≥1,k≥1。正整数n的这种表示称为正整数n的划分。求正整数n的不同划分个数。二、实验设备(环境)及要求PC机,WindowsXP,Myeclipse三、实验内容要求五、分析讨论六、教师评语
2、1.按时完成实验;2.实验内容和过程记录完整;3.回答问题完整、正确;4.有实验的心得或讨论;5.实验报告的撰写认真、格式符合要求,没有抄袭行为。签名:日期:成绩本实验的操作步骤如下。棋盘覆盖:代码:classChessBoardWithTriomino{privateintsize;privateint[][]board;privateinttile=0;publicChessBoardWithTriomino(intsize){//构造函数if(nCF2(size)==true)this.size=size;}publicvoidCreateBoard(){board=newint[si
3、ze][size];}publicbooleannCF2(intn){booleanb=false;intx=2;while(true){if(x==n){b=true;break;}if(x4、r+s&&dc=tc+s)//特殊方格在此棋盘中CB(tr,tc+s,dr,dc,s);else{board[tr+s-1][tc+s]=t;//覆盖其余方格CB(tr,tc+s,tr+s-1,tc+s,s);}//覆盖左下角子棋盘if(dr>=tr+s&&dc5、(tr+s,tc,dr,dc,s);else{//用t号L型骨牌覆盖右上角board[tr+s][tc+s-1]=t;//覆盖其余方格CB(tr+s,tc,tr+s,tc+s-1,s);}//覆盖右下角子棋盘if(dr>=tr+s&&dc>=tc+s)//特殊方格在此棋盘中CB(tr+s,tc+s,dr,dc,s);else{//用t号L型骨牌覆盖左上角board[tr+s][tc+s]=t;//覆盖其余方格CB(tr+s,tc+s,tr+s,tc+s,s);}returntrue;}publicvoidprint(){for(inti=0;i6、size;j++){System.out.print(board[i][j]+"t");}System.out.println("");}}}publicclasstriomino{publicstaticvoidmain(String[]args){ChessBoardWithTriominocbt=newChessBoardWithTriomino(8);cbt.CreateBoard();if(cbt.CB(0,0,4,5,cbt.getSize())==true)cbt.print();}}运行结果:整数规划:代码:classZSHF{privateintn;privateintn7、um;publicZSHF(intn){this.n=n;}publicvoidsetN(intn){this.n=n;}publicintgetN(){returnn;}publicvoidsetNum(intm,intn,Stringstr){num=q(m,n,str);}publicintgetNum(){returnnum;}publicintq(intm,intn,Stringstr){if((m
4、r+s&&dc=tc+s)//特殊方格在此棋盘中CB(tr,tc+s,dr,dc,s);else{board[tr+s-1][tc+s]=t;//覆盖其余方格CB(tr,tc+s,tr+s-1,tc+s,s);}//覆盖左下角子棋盘if(dr>=tr+s&&dc5、(tr+s,tc,dr,dc,s);else{//用t号L型骨牌覆盖右上角board[tr+s][tc+s-1]=t;//覆盖其余方格CB(tr+s,tc,tr+s,tc+s-1,s);}//覆盖右下角子棋盘if(dr>=tr+s&&dc>=tc+s)//特殊方格在此棋盘中CB(tr+s,tc+s,dr,dc,s);else{//用t号L型骨牌覆盖左上角board[tr+s][tc+s]=t;//覆盖其余方格CB(tr+s,tc+s,tr+s,tc+s,s);}returntrue;}publicvoidprint(){for(inti=0;i6、size;j++){System.out.print(board[i][j]+"t");}System.out.println("");}}}publicclasstriomino{publicstaticvoidmain(String[]args){ChessBoardWithTriominocbt=newChessBoardWithTriomino(8);cbt.CreateBoard();if(cbt.CB(0,0,4,5,cbt.getSize())==true)cbt.print();}}运行结果:整数规划:代码:classZSHF{privateintn;privateintn7、um;publicZSHF(intn){this.n=n;}publicvoidsetN(intn){this.n=n;}publicintgetN(){returnn;}publicvoidsetNum(intm,intn,Stringstr){num=q(m,n,str);}publicintgetNum(){returnnum;}publicintq(intm,intn,Stringstr){if((m
5、(tr+s,tc,dr,dc,s);else{//用t号L型骨牌覆盖右上角board[tr+s][tc+s-1]=t;//覆盖其余方格CB(tr+s,tc,tr+s,tc+s-1,s);}//覆盖右下角子棋盘if(dr>=tr+s&&dc>=tc+s)//特殊方格在此棋盘中CB(tr+s,tc+s,dr,dc,s);else{//用t号L型骨牌覆盖左上角board[tr+s][tc+s]=t;//覆盖其余方格CB(tr+s,tc+s,tr+s,tc+s,s);}returntrue;}publicvoidprint(){for(inti=0;i6、size;j++){System.out.print(board[i][j]+"t");}System.out.println("");}}}publicclasstriomino{publicstaticvoidmain(String[]args){ChessBoardWithTriominocbt=newChessBoardWithTriomino(8);cbt.CreateBoard();if(cbt.CB(0,0,4,5,cbt.getSize())==true)cbt.print();}}运行结果:整数规划:代码:classZSHF{privateintn;privateintn7、um;publicZSHF(intn){this.n=n;}publicvoidsetN(intn){this.n=n;}publicintgetN(){returnn;}publicvoidsetNum(intm,intn,Stringstr){num=q(m,n,str);}publicintgetNum(){returnnum;}publicintq(intm,intn,Stringstr){if((m
6、size;j++){System.out.print(board[i][j]+"t");}System.out.println("");}}}publicclasstriomino{publicstaticvoidmain(String[]args){ChessBoardWithTriominocbt=newChessBoardWithTriomino(8);cbt.CreateBoard();if(cbt.CB(0,0,4,5,cbt.getSize())==true)cbt.print();}}运行结果:整数规划:代码:classZSHF{privateintn;privateintn
7、um;publicZSHF(intn){this.n=n;}publicvoidsetN(intn){this.n=n;}publicintgetN(){returnn;}publicvoidsetNum(intm,intn,Stringstr){num=q(m,n,str);}publicintgetNum(){returnnum;}publicintq(intm,intn,Stringstr){if((m
此文档下载收益归作者所有