nyoj 43 24 Point game
来源:互联网 发布:战争是必然的 知乎 编辑:程序博客网 时间:2024/05/16 01:44
http://acm.nyist.net/JudgeOnline/problem.php?pid=43
分析:因为精度改了一天,我说怎么看逻辑都没有问题……
加、减、乘、除、被加、被减,然后遍历
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;const int NM=15;const double eps=1e-6;bool vis[NM],flag;double a[NM];int n,m,k;void DFS(double ans,int num){if(flag) return;if(num==n){if(fabs(ans-m)<eps) //!!flag=true;return;}for(int i=1;i<=n;i++){if(!vis[i]){vis[i]=1;if(num==0) DFS(a[i],num+1);else{for(int j=0;j<6;j++){switch(j){case 0:DFS(ans+a[i],num+1);break;case 1:DFS(ans*a[i],num+1);break;case 2:DFS(ans-a[i],num+1);break;case 3:DFS(a[i]-ans,num+1);break;case 4:if(a[i]!=0) DFS(ans/a[i],num+1);break;case 5:if(ans!=0) DFS(a[i]/ans,num+1);break;}}}vis[i]=0; //}}}int main(){int T,i;scanf("%d",&T);while(T--){cin>>n>>m;for(i=1;i<=n;i++) cin>>a[i];flag=false;DFS(0,0);if(flag) cout<<"Yes"<<endl;else cout<<"No"<<endl;}return 0;}
0 0
- Nyoj 43 24 Point game
- NYOJ-43 24 Point game
- 24 Point game(nyoj 43)
- nyoj 43 24 Point game
- NYOJ 43 24 Point game
- nyoj 24 Point game
- nyoj-43 24 Point game (搜索)
- NYOJ-43 24 Point game-DFS
- Nyoj 43 24 Point game 【DFS】
- NYOJ 43--24 Point game【DFS】
- 深搜 nyoj 43 24 Point game
- nyoj 43 24 Point game 【经典DFS】
- nyoj 43 24 Point game 【dfs&&递归】
- NYOJ 43 24 Point game (DFS)
- NYOJ 43 24 Point game(dfs)
- NYOJ 43 —24 Point game
- Nyoj 24 Point game dfs
- nyoj 42 24 Point game
- Navigation Bar 修改问题(二)---- Launcher与应用之间切换
- Android JNI调用(二)
- 停止事件流
- Effective C++之std::tr1::shared_ptr的使用
- Android JNI调用(三)
- nyoj 43 24 Point game
- [数据结构] KMP字符串匹配
- 通过添加按钮打开文件选取歌曲,并且添加到列表中(listbox)并保存在数据库中
- 用户配置文件(passwd/shadow)
- Navigation Bar 修改问题(三) ----- 系统重启Launcher界面显示Nv Bar
- 装饰模式
- UVa 11205 - The broken pedometer
- Poj 3685 Matrix
- DevStore独家点评:腾讯信鸽推送服务