UVa:10344 23 out of 5
来源:互联网 发布:学编程还是网页设计好 编辑:程序博客网 时间:2024/05/21 06:27
简单回溯。要用到全排列。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int x[10];bool ok=false;void dfs(int pos,int res){ if(pos==6) { if(res==23) ok=true; return; } else { dfs(pos+1,res+x[pos]); dfs(pos+1,res-x[pos]); dfs(pos+1,res*x[pos]); }}int main(){ while(scanf("%d%d%d%d%d",&x[1],&x[2],&x[3],&x[4],&x[5])&&!(!x[1]&&!x[2]&&!x[3]&&!x[4]&&!x[5])) { sort(x+1,x+6); ok=false; do { dfs(2,x[1]); if(ok) break; } while(next_permutation(x+1,x+6)); if(ok) puts("Possible"); else puts("Impossible"); } return 0;}
- Uva 10344 23 out of 5
- uva 10344 - 23 out of 5
- uva 10344 - 23 out of 5
- uva-10344 - 23 out of 5
- UVa 10344 - 23 out of 5
- uva 10344 - 23 out of 5
- UVa 10344 23 out of 5
- uva 10344 23 out of 5(DFS)
- UVA 10344 23 out of 5
- uva-10344 - 23 out of 5
- UVa:10344 23 out of 5
- uva 10344 23 out of 5
- uva 10344 23 Out of 5
- [回溯]23 out of 5 UVA 10344
- UVa 10344 - 23 out of 5
- UVa 10344 - 23 out of 5
- UVA 10344 - 23 out of 5
- uva-10344 - 23 out of 5
- V4L2编程
- Objective-C学习笔记(二)–Category和Extension
- hashcode的作用
- ubuntu10.10 遇到Waiting for headers
- Motion Deblurring图像运动去模糊代码
- UVa:10344 23 out of 5
- Ajax工作原理
- 两台电脑用网线如何连接?
- hdfs集群启动——概述(1)
- Linux与VxWorks主要区别(一):内核结构
- android:ScrollView嵌套ListView的问题
- Linux就是这个范儿之第一次亲密接触(2)
- hdu 4424 Conquer a New Region(并查集)
- Linux就是这个范儿之第一次亲密接触(3)