递推dp(uva10404)
来源:互联网 发布:单机免费进销存软件 编辑:程序博客网 时间:2024/06/05 07:47
Bachet's Game
Time Limit:6666MS Memory Limit:Unknown 64bit IO Format:%lld & %llu
Description
Problem B: Bachet's Game
Bachet's game is probably known to all but probably not by this name. Initially there aren stones on the table. There are two players Stan and Ollie, who move alternately. Stan always starts. The legal moves consist in removing at least one but not more thank stones from the table. The winner is the one to take the last stone.Here we consider a variation of this game. The number of stones that can be removed in a single move must be a member of a certain set ofm numbers. Among the m numbers there is always 1 and thus the game never stalls.
Input
The input consists of a number of lines. Each line describes one game by a sequence of positive numbers. The first number isn <= 1000000 the number of stones on the table; the second number ism <= 10 giving the number of numbers that follow; the last m numbers on the line specify how many stones can be removed from the table in a single move.Input
For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly.Sample input
20 3 1 3 821 3 1 3 822 3 1 3 823 3 1 3 81000000 10 1 23 38 11 7 5 4 8 3 13999996 10 1 23 38 11 7 5 4 8 3 13
Output for sample input
Stan winsStan winsOllie winsStan winsStan winsOllie wins
题意:两个人做游戏,有n块石字,m堆,每个人每次只能取m堆数量中的个数,问谁会赢
思路:dp[i]表示还剩i个是S能不能赢,那么当dp[i-a[j]]为偶数,S就可以赢
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>using namespace std;const int maxn=1000100;int dp[maxn];int a[maxn];int N,M;int main(){ while(scanf("%d",&N)!=EOF) { scanf("%d",&M); for(int i=1;i<=M;i++)scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) if(i>=a[j]&&dp[i-a[j]]==0)dp[i]=1; if(dp[N])printf("Stan wins\n"); else printf("Ollie wins\n"); } return 0;}
0 0
- 递推dp(uva10404)
- uva10404 - Bachet's Game(博弈,递推)
- uva10404(DP 取石子)
- uva10404
- 递推(dp)-HDU5366
- uva10404 Bachet’s Game(dp之取石子游戏的胜负)
- POJ 2229 Sumsets(dp 递推)
- uva1638(递推关系,dp)
- B. Working out (递推dp )
- POJ2385 Apple Catching(DP/递推)
- 3046(dp优化递推关系式)
- hihocoder#1239 : Fibonacci(递推DP)
- hdu1438 dp递推
- poj3786(DP,递推)
- hdu4489 dp+递推
- hdu5375 dp+递推
- hdu5286 dp+递推
- 期望dp递推
- 信号报告
- Progress事件
- iOS 单元测试
- 第0章
- 【BZOJ 2743】 [HEOI2012]采花
- 递推dp(uva10404)
- 第一章
- golang 中使用数组创建slice时的注意事项
- libpcap的使用一(pcap_lookupdev函数的使用)
- 解决pomelo官方的chat例子不好用的问题
- swift学习记录(实例方法和类型方法)
- C++引用与指针的区别
- jdk环境变量配置
- 【java编程】IO流之得到指定目录下.java文件的绝对路径