UVA - 10404 Bachet's Game
来源:互联网 发布:bt天堂新域名 编辑:程序博客网 时间:2024/05/20 06:31
题意:给n个石头,m 种取法,Stan先取,Ollie后取,取到最后一块的获胜,问谁赢了,首先我们想想怎么能让Stan获胜,一定是Ollie取完后,我们可以通过m种取法中的一种使得Stan拿到最后一块,那么我们用dp[i] = 1表示Stan赢,0为输,那么一定有dp[n-arr[i] ] == 0,那么Stan 就赢了,推广到一般的情况是只要dp[i-arr[j]] == 0,那么我们就可以说在i个石头的情况下Stan赢了,这样我们就得到了状态转移方程 if(i>=arr[j] && dp[i-arr[j]]==0)dp[i]=1; 所以我们第一块石头开始判断,只要dp[n] == 1 ,那么Stan 就是赢家
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAXN = 1000005;int dp[MAXN];int arr[MAXN];int n,m;int main(){ while (scanf("%d%d",&n,&m) != EOF){ memset(dp,0,sizeof(dp)); for (int i = 1; i <= m; i++){ scanf("%d",&arr[i]); dp[arr[i]] = 1; } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (i >= arr[j] && !dp[i-arr[j]]){ dp[i] = 1; break; } if (dp[n]) printf("Stan wins\n"); else printf("Ollie wins\n"); } return 0;}
- uva 10404 Bachet's Game
- UVA 10404 Bachet's Game
- UVa 10404 - Bachet's Game
- UVa 10404 - Bachet's Game
- uva 10404 - Bachet's Game
- UVa 10404 - Bachet's Game
- UVa 10404 - Bachet's Game
- Uva-10404-Bachet's Game
- UVa:10404 Bachet's Game
- UVA - 10404 Bachet's Game
- UVa 10404 - Bachet's Game
- uva 10404 Bachet's Game
- UVA 10404 Bachet's Game
- UVA-10404-Bachet's Game
- UVA 10404 Bachet's Game
- UVA 10404 Bachet's Game
- UVA 10404 Bachet's Game
- uva 10404 Bachet's Game
- 黑马程序员Java基础__多线程
- 磁场传感器(指北针)
- 父子进程同步的功臣——wait
- 通过地址重写访问动态Web
- 计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接
- UVA - 10404 Bachet's Game
- 【MySQL】关于数据库连接超时
- C/C++ 排列组合问题(递归)
- 进程控制地字第1号系统调用——exec
- extern “C” 的作用
- 使用POST提交数据
- 读取网络图片
- Echo程序
- 2012 浙大考研上机题汇总