Boxes and Stones - UVa 12525 dp
2014-08-31 20:48
453 查看
题意:有n个小球,m个盒子,小球被分配到1到m-1的盒子中,每次P选定其中的一部分小球,C可以选择保留或不保留选定的球,若保留,这些球都向移动到其右边的盒子,剩下的剔除,反之亦然。如果有球到m盒子时P就赢了。问C赢的话,开局的方式有多少种。
思路:如果一种局面使得C必胜时,从左往右计数球的个数,将每个盒子中的球数除以2,折算到它右边的盒子中,最终使得m盒子没有球的情况,就是C必胜的情况。这个想法是从4 1 0 和4 2 0 这种情况考虑发现的。
dp[m]
[k]表示到第m个格子,用了n个球,且第m个格子折算后的数为k的情况数量。
AC代码如下:
思路:如果一种局面使得C必胜时,从左往右计数球的个数,将每个盒子中的球数除以2,折算到它右边的盒子中,最终使得m盒子没有球的情况,就是C必胜的情况。这个想法是从4 1 0 和4 2 0 这种情况考虑发现的。
dp[m]
[k]表示到第m个格子,用了n个球,且第m个格子折算后的数为k的情况数量。
AC代码如下:
#include<cstdio> #include<cstring> using namespace std; typedef long long ll; ll dp[110][210][410],MOD=1e9+7; int main() { int i,j,k,n,m; dp[0][0][0]=1; for(i=1;i<=100;i++) for(j=0;j<=200;j++) { dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1])%MOD; for(k=0;k<=200;k++) dp[i][j][k]=(dp[i][j-1][k-1]+dp[i-1][j][k*2]+dp[i-1][j][k*2+1])%MOD; } while(~scanf("%d%d",&n,&m)) printf("%lld\n",dp[m] [0]); }
相关文章推荐
- UVa 12525 Boxes and Stones (dp 博弈)
- UVa 12525 Boxes and Stones (dp 博弈)
- HihoCoder - 1636 Pangu and Stones——区间dp
- UVA 10635 Prince and Princess DP LIS
- Stamps and Envelope Size - UVa 242 dp
- UVALive 5088 Alice and Bob's Trip(树形DP)
- UVA 1484 Alice and Bob's Trip (树形dp)
- 2017ICPC北京-J Pangu and Stones 【区间DP】
- J - Pangu and Stones HihoCoder - 1636 (区间DP)
- UVa 242 Stamps and Envelope Size (无限背包,DP)
- UVA_103 Stacking boxes(DP)
- UVA 10635 Prince and Princess DP LIS
- uva1484 Alice and Bob's Trip (树形dp)
- UVA 10154 Weights and Measures(贪心+DP最长上升子序列)
- Pangu and Stones(区间dp)
- uva 1484 Alice and Bob's Trip (树形dp)
- hihocoder 1636 : Pangu and Stones(区间dp)
- UVa 103 Stacking Boxes 堆砌盒子(DP 最长条件子序列)
- UVA1484 Alice and Bob's Trip(树形dp)
- UVA 12063 Zeros and Ones (数位dp)