sgu153:Playing with matches
来源:互联网 发布:matlab字符串数组赋值 编辑:程序博客网 时间:2024/06/02 10:22
题意:
一个取火柴游戏,可以取的数在一个集合S内,S必包含1,且不超过9个数,每个数都不大于9.最后取完者失败。
求n(n<10^9)根火柴时先取的胜利还是后取的胜利.
分析:
貌似有一种dp方程f[i]=max(f[i-P[j]]^1)
然后打个表貌似还有规律吧,而且规律好像也不长额,所以暴力找一下就好啦...#include <cstdio>#include <cstring>using namespace std;const int MAXM = 10, MAXP = 505;int N, M, P[MAXM], r;bool f[MAXP], cap[MAXP];int main(){int K;scanf("%d", &K);while(K--){memset(P, 0, sizeof(P));memset(f, 0, sizeof(f));memset(cap, 0, sizeof(cap));scanf("%d%d", &N, &M);P[1] = 1;M++;for(int i = 2; i <= M; ++i)scanf("%d", P+i);cap[0] = true;f[0] = true;for(int i = 1; i < 40; ++i)for(int j = 1; j <= M; ++j)if(i-P[j] >= 0 && cap[i-P[j]])f[i] |= f[i-P[j]]^1, cap[i] = true; r = 0;for(int i = 18; i >= 1 && !r; --i)for(int j = 0; j < i; ++j){if(f[j] != f[j+i]) break;if(j == i-1) r = i;}if(f[N%r])puts("FIRST PLAYER MUST WIN");else puts("SECOND PLAYER MUST WIN");}return 0;}
0 0
- sgu153:Playing with matches
- sgu153: Playing with matches
- sgu153 Playing with matches (博弈dp)#by nobody
- sgu 153 Playing with matches
- SGU 153 - Playing with matches(博弈)
- SGU 153 Playing with matches(博弈)
- sgu 153 Playing with matches DP+枚举循环节
- SGU 153 Playing with matches (博弈,循环节)
- Playing with DataGrid Control
- Playing with ptrace
- Playing with the Stack
- Playing with the Stack
- Playing with the stack
- playing with ptrace
- Playing with Virtual Memory
- FZU_1017 Playing with Calculator
- 10067 - Playing with Wheels
- Playing with Virtual Memory
- win8.1 开机以后输入法不见了,解决办法
- 跟我一起写makefile 一
- 数据结构第四章字符串与数组
- struts2命名规则
- interleave词组
- sgu153:Playing with matches
- python从apk文件中获取app的名字
- 极路由2-极贰9007的降级root攻略
- C语言中union与大小端模式的理解
- Balanced Binary Tree
- json预习与自学
- javascript简易日历
- [SDOI2009]晨跑
- Installing VMware Tools in a Linux virtual machine using a Compiler (1018414)