POJ 1014
来源:互联网 发布:口袋弹弓 淘宝 编辑:程序博客网 时间:2024/05/16 04:54
感想:这次是借鉴别人的,写了很久都是超时,好菜啊我。。。。。
代码:http://blog.csdn.net/li4951/article/details/7434598
#include<iostream>using namespace std;int amount[7] = {0};int half_value = 0;int flag = 0;void DFS(int value, int pre){if(value == half_value){flag = 1;return;}if(flag == 1){//当已经完成时,结束所有父层递归return;}int i = 0;for(i = pre; i > 0; i--){//这里i从大到小是为了快一点到half_value,剪枝效果明显一点if(amount[i]){if(i + value <= half_value){amount[i]--;DFS(i + value, i);if(flag == 1){//当已经完成时,结束本层的其他递归return;}}}}}int main(){int testcase = 1;while(true){flag = 0;int totalvalue = 0;int N = 6;int i = 1;while(i <= N){cin >> amount[i];totalvalue += amount[i] * i;i++;}if(!totalvalue){break;}printf("Collection #%d:\n", testcase++);if(totalvalue % 2 != 0){cout << "Can't be divided." << endl << endl;continue;}half_value = totalvalue / 2;DFS(0, 6);if(flag){cout << "Can be divided." << endl;} else {cout << "Can't be divided." << endl;}cout << endl;}return 0;}
0 0
- POJ 1014
- poj 1014
- poj 1014
- POJ 1014
- poj 1014
- poj 1014
- poj 1014
- POJ 1014
- poj 1014
- POJ 1014 Dividing
- POJ 1014 Dividing
- poj 1014 Dividing
- poj 1014Dividing
- POJ 1014 Dividing
- poj 1014 装箱问题
- 【多重背包】POJ 1014
- POJ 1014 多重背包
- poj 1014 硬币分割
- 快速排序
- Android初始化OpenGL ES,并且分析Renderer子线程原理
- 二进制中负数的表示
- aaa
- 抽象类的应用
- POJ 1014
- HRBUST
- HDU-1584-蜘蛛牌(DFS)
- Scanner及String类总结
- php内存管理之垃圾回收机制
- 修改hosts不必重启 立刻生效
- 第四周:[Leetcode]210. Course Schedule II
- 【C++】继承总结
- DbUtils(一) 结果集概览