第十五周周四总结
来源:互联网 发布:大胃王密子君的淘宝店 编辑:程序博客网 时间:2024/04/19 16:32
这几天有点懈怠了。。。这几天做的看的这几道题感觉比之前题要难了。
Find the number of ways to tile an m*n rectangle with long dominoes -- 3*1 rectangles.
Each domino must be completely within the rectangle, dominoes must not overlap (of course, they may touch each other), each point of the rectangle must be covered.
The input contains several cases. Each case stands two integers m and n (1 <= m <= 9, 1 <= n <= 30) in a single line. The input ends up with a case of m = n = 0.
<p< dd="">
Output the number of ways to tile an m*n rectangle with long dominoes.
<p< dd="">
3 33 100 0
<p< dd="">
228
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int n,m,state[10],ss[20];long long dp[32][20005];void dfs(int p,int sstate,int now,int pp){if(p==n) { dp[now+1][sstate]+=dp[now][pp]; return; }if(!ss[p]) { if(p+3<=n&&!ss[p+2]&&!ss[p+1]) dfs(p+3,sstate,now,pp); dfs(p+1,sstate+2*state[p],now,pp); }else if(ss[p]==1) dfs(p+1,sstate,now,pp);else dfs(p+1,sstate+state[p],now,pp);}int main(){state[0]=1;for(int i=1;i<10;i++) state[i]=state[i-1]*3;while(cin>>n>>m&&n+m) { if(n*m%3!=0) { cout<<0<<endl; continue; } memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=0;i<m;i++) for(int j=0;j<state[n];j++) if(dp[i][j]) { memset(ss,0,sizeof(ss)); if(j) { int jj=j; int p=-1; while(jj>0) { ss[++p]=jj%3; jj/=3; } } dfs(0,0,i,j); } cout<<dp[m][0]<<endl; }return 0;}
刚适应了二进制一换成三进制有点不适应。记得这道题以前用的暴力模拟做的,然后超时,当时做题还没遇到过几次超时,haha。
Several friends are planning to take tourism during the next holiday. They have selected some places to visit. They have decided which place to start their tourism and in which order to visit these places. However, anyone can leave halfway during the tourism and will never back to the tourism again if he or she is not interested in the following places. And anyone can choose not to attend the tourism if he or she is not interested in any of the places.
Each place they visited will cost every person certain amount of money. And each person has a positive value for each place, representing his or her interest in this place. To make things more complicated, if two friends visited a place together, they will get a non negative bonus because they enjoyed each other’s companion. If more than two friends visited a place together, the total bonus will be the sum of each pair of friends’ bonuses.
Your task is to decide which people should take the tourism and when each of them should leave so that the sum of the interest plus the sum of the bonuses minus the total costs is the largest. If you can’t find a plan that have a result larger than 0, just tell them to STAY HOME.
Each place they visited will cost every person certain amount of money. And each person has a positive value for each place, representing his or her interest in this place. To make things more complicated, if two friends visited a place together, they will get a non negative bonus because they enjoyed each other’s companion. If more than two friends visited a place together, the total bonus will be the sum of each pair of friends’ bonuses.
Your task is to decide which people should take the tourism and when each of them should leave so that the sum of the interest plus the sum of the bonuses minus the total costs is the largest. If you can’t find a plan that have a result larger than 0, just tell them to STAY HOME.
A case starting with 0 0 indicates the end of input and you needn’t give an output.
2 1101550 55 03 230 5024 4840 7035 200 4 14 0 51 5 02 2100 10050 5050 500 2020 00 0
541STAY HOME
#include<iostream>#include<string.h>#include<stdio.h>#include<vector>#include<math.h>using namespace std;int n,m;int money[11],fun[11][11],together[11][11];int dp[1<<10][11],ss[1<<20][11];vector<int>state[1<<10];void solve(){int up=1<<n;for(int i=0;i<up;i++) for(int j=0;j<up;j++) if((i&j)==j) state[i].push_back(j);for(int i=0;i<up;i++) { int s=0,p=0; for(int j=0;j<n;j++) { if(i&(1<<j)) { p++; for(int k=0;k<j;k++) if(i&(1<<k)) s+=together[j][k]; } } for(int j=0;j<m;j++) { ss[i][j]=s; ss[i][j]-=p*money[j]; for(int k=0;k<n;k++) if(i&(1<<k)) ss[i][j]+=fun[k][j]; } }for(int i=0;i<up;i++) { for(int j=0;j<m;j++) dp[i][j]=-999999999; dp[i][0]=ss[i][0]; }for(int i=1;i<m;i++) for(int j=0;j<up;j++) for(int k=0;k<state[j].size();k++) dp[state[j][k]][i]=max(dp[state[j][k]][i],dp[j][i-1]+ss[state[j][k]][i]);}void csh(){for(int i=0;i<(1<<10);i++) state[i].clear();}int main(){while(cin>>n>>m&&n+m) { for(int i=0;i<m;i++) scanf("%d",&money[i]); for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&fun[i][j]); for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&together[i][j]); csh(); solve(); int ans=-999999999; int up=1<<n; for(int i=0;i<up;i++) ans=max(ans,dp[i][m-1]); if(ans<=0) cout<<"STAY HOME"<<endl; else cout<<ans<<endl; }return 0;}
这道题写起来感觉超麻烦,看着大神们的代码想了好久。。。
阅读全文
0 0
- 第十五周周四总结
- 第十五周周末总结
- 2017.12.10第十五周周总结
- 第一周周四总结
- 第二周周四总结
- 第三周周四总结
- 第四周周四总结
- 第五周周四总结
- 第七周周四总结
- 第八周周四总结
- 第九周周四总结
- 第十周周四总结
- 第十二周周四总结
- 第十三周周四总结
- 第十六周周四总结
- 2017.12.7第十五周周中总结
- 第十五周周报
- 第十五周周报
- 求三角形面积
- 深入理解Android音视频同步机制(三)NuPlayer的avsync逻辑
- java 类的继承
- 网站不带WWW访问时矢量字体加载不出来 网站重定向
- Android中的事件分发机制
- 第十五周周四总结
- 7-2 一帮一(10 分) “一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名
- 探讨一下常见支付系统的对外接口
- 查资料
- 从CentOS安装完成到生成词云python学习日记
- Mongodb相关
- JAVA之排序
- 学习笔记3
- 【python】【穆晨】【171207】连续第五十八天总结