10400 - Game Show Math
来源:互联网 发布:雅士尼处理器软件 编辑:程序博客网 时间:2024/06/05 16:02
用状态方程来剪枝的一种方式
# include<stdio.h># include<stdlib.h># include<string.h>int dfs(long ans,int cur);int range(long a);long number[105],que;int n,vis[64010][110];char record[105];int main(){int test;scanf("%d",&test);record[0]=0;while(test--){ scanf("%d",&n); for(int i=0;i<n;i++)scanf("%ld",&number[i]); scanf("%ld",&que); memset(vis,0,sizeof(vis)); if(dfs(number[0],1)) { printf("%ld",number[0]); for(int i=1;i<n;i++) { printf("%c%ld",record[i],number[i]); } printf("=%ld\n",que); continue; } printf("NO EXPRESSION\n");}return 0;}int dfs(long ans,int cur){if(vis[ans+32000][cur])return 0;vis[ans+32000][cur]=1;if(cur==n){if(ans==que)return 1;elsereturn 0;}if(range(ans+number[cur])&&dfs(ans+number[cur],cur+1)){record[cur]='+';return 1;}if(range(ans-number[cur])&&dfs(ans-number[cur],cur+1)){record[cur]='-';return 1;}if(range(ans*number[cur])&&dfs(ans*number[cur],cur+1)){record[cur]='*';return 1;}if(range(ans/number[cur])&&ans%number[cur]==0&&dfs(ans/number[cur],cur+1)){record[cur]='/';return 1;}return 0;}int range(long a){if(abs(a)<=32000)return 1;elsereturn 0;}
0 0
- 10400 - Game Show Math
- 10400 game show math
- 10400 - Game Show Math
- 10400 -Game Show Math
- UVa 10400 - Game Show Math
- uva 10400 - Game Show Math
- uva 10400 - Game Show Math
- 10400 - Game Show Math------水题
- UVa 10400 - Game Show Math
- UVA 10400 - Game Show Math
- uva 10400 Game Show Math
- uva 10400 Game Show Math
- UVA 10400 Game Show Math
- uva 10400 Game Show Math
- UVa 10400 - Game Show Math
- uva 10400 - Game Show Math
- UVA - 10400 Game Show Math
- UVa 10400 - Game Show Math
- 前缀式计算(nyoj 128)
- 获取电池电量的方法
- UVa:1513 Movie collection
- 人际交流
- python数据结构与算法 6栈的应用之符号平衡(通用)
- 10400 - Game Show Math
- Sicily10359(优先队列)
- POJ 1195 Mobile phones
- LeetCode Best Time to Buy and Sell Stock II
- zoj 2975 Kinds of Fuwas(数学题)
- 12款很棒的浏览器兼容性测试工具推荐
- Handler的使用
- (libgdx学习)compass(指南针)
- 苹果帮助文档