codeforces 339C
来源:互联网 发布:网络推手阿建电话 编辑:程序博客网 时间:2024/06/04 18:13
题目链接:http://codeforces.com/problemset/problem/339/C
题目大意:
有不同质量的砝码无限多个,现在只让你在天平两边放入m个,要求
1.每次在天平放一个,一次左边,下一次右边
2.相邻两次质量必须不同
3.放入砝码后,保证放入的这边总重严格大于另外一边。
题目求解:简单的dfs即可~
#include<iostream>using namespace std;int dfs(int step,int left,int right,int last,int record[],const int m,const int b[],const int jmax){ int cur = (step%2 == 0)?right:left; int other = (step%2 == 1)?right:left; if(step > m) { return 0; } for(int j = 1; j <= jmax;j++) { if((last != b[j] || last == 0) && b[j]+cur>other) { int ltemp = left,rtemp = right; if(left == cur) ltemp += b[j]; else rtemp += b[j]; record[step] = b[j]; if(step == m) { cout<<"YES"<<endl; for(int i = 1; i <= m;i++) { if(i<m) cout<<record[i]<<" "; else cout<<record[i]; } return 1; } if(dfs(step+1,ltemp,rtemp,b[j],record,m,b,jmax)) return 1; record[step] = 0; } } return 0;}int main(){ char s[20]; cin>>s; int b[11] = {0}; int record[1002] = {0}; int j = 1; for(int i = 0; i<= 9;i++) { if(s[i] == '1') b[j++] = i+1; } int jmax = j-1; int m; cin>>m; if(dfs(1,0,0,0,record,m,b,jmax) == 0) cout<<"NO"; return 0;}
- codeforces 339C
- CODEFORCES #339 div2 C
- CodeForces 339C
- Codeforces 339C Xenia and Weights
- Codeforces Round #339 (Div. 2) C.cpp
- codeforces 339C 记忆化搜索
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- codeforces 339C C. Xenia and Weights(dp)
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- Oracle/PLSQL中的一个函数--NVL函数
- 增强的单据通esb插件任务调度策略及配置
- 分布式拒绝服务攻击(DDoS)原理及防范
- Oracle 中的JOIN
- 如何优化网页转化率?(上篇)
- codeforces 339C
- JS精华入门之【一】
- JScript实现将指定目录下的vc工程加到解决方案
- IT求职经验总结——面试和准备策略
- Oracle natural join(自然连接)
- 解决Ubuntu SSH登录时过慢的问题
- android webview内容压线问题解决方法
- IT职场中外企面试最爱提的问题TOP10
- 行业深思-IT行业是吃青春饭吗