HDU 4301 Divide Chocolate DP

题目链接~http://acm.hdu.edu.cn/showproblem.php?pid=4301

非原创,看了好几个大神的题解,才看懂

代码::刚开始看bin神的,看了半天没看懂,我太菜了  %>_<%

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 /*
 5    dp[i][j][0] 表示前i行出现了j部分 且第i行那两个不是一部分的
 6    dp[i][j][1] 表示前i行出现了j部分 且第i行那两个是一部分的
 7
 8    状态的话
 9    第一种情况是  在第i行j不变
10    dp[i][j][1]=dp[i-1][j][0]*2+dp[i-1][j][1] ;   dp[i][j][0]=dp[i-1][j][0];
11
12    第二种情况是  在第i行j+1
13    dp[i][j][1]=dp[i-1][j-1][0]+dp[i-1][j-1][1];  dp[i][j][0]=2*dp[i-1][j-1][1]+2*dp[i-1][j-1][0];
14    第三种情况是  在第i行j+2
15    dp[i][j][0]=dp[i-1][j-2][1]+dp[i-1][j-2][0];
16 */
17
18 int dp[1005][2005][3]={0};
19 int main()
20 {
21     int n,x,y;
22     dp[1][1][1]=1;dp[1][2][0]=1;
23     for(int i=2;i<=1002;i++)
24     {
25         for(int j=1;j<=i*2;j++)
26         {
27             dp[i][j][1]=(2*dp[i-1][j][0]+dp[i-1][j][1]+dp[i-1][j-1][0]+dp[i-1][j-1][1])%100000007;
28             dp[i][j][0]=(dp[i-1][j][0]+2*dp[i-1][j-1][1]+2*dp[i-1][j-1][0]+dp[i-1][j-2][0]+dp[i-1][j-2][1])%100000007;
29         }
30     }
31     scanf("%d",&n);
32     while(n--)
33     {
34         scanf("%d%d",&x,&y);
35         printf("%d\n",(dp[x][y][1]+dp[x][y][0])%100000007);
36     }
37     return 0;
38 }  
时间: 2024-10-12 22:17:25

HDU 4301 Divide Chocolate DP的相关文章

HDU 4301 Divide Chocolate(DP)

http://acm.hdu.edu.cn/showproblem.php?pid=4301 题意: 有一块n*2大小的巧克力,现在某人要将这巧克力分成k个部分,每个部分大小随意,问有多少种分法. 思路: dp [ i ] [ j ] [ 0/1 ]表示到第 i 列时分成 j 块的方案数,0/1表示第 i 列的两格巧克力是否相连. 这样的话,分析到第 i 块时的情况如下: ①块数不变 dp[i][j][1] = dp[i][j][1] + dp[i-1][j][0]*2 dp[i][j][0]

hdu 4301(基本dp)

题意:就是给你一块2*n的巧克力,让你把它分成x块,并且每一个单位的巧克力各不相同,问有多少种分法? 分析:用dp[i][j][k],表示到巧克力的第二列时,巧克力被分成了j快,k用来表示第i列上下两块是分开的还是在一起的,在纸上把所有的情况画一下,于是就得到状态方程: dp[i][j][0]=(dp[i-1][j][1]*2+dp[i-1][j][0]+dp[i-1][j-1][0]+dp[i-1][j-1][1])%mod; dp[i][j][1]=(dp[i-1][j][1]+dp[i-1

HDU 5783 Divide the Sequence(数列划分)

HDU 5783 Divide the Sequence(数列划分) Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfy

HDU 4960 (水dp)

Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xi

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

hdu 2296 aC自动机+dp(得到价值最大的字符串)

Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3180    Accepted Submission(s): 1033 Problem Description For the hope of a forever love, Steven is planning to send a ring to Jane with a rom

hdu 2457 AC自动机+dp

DNA repair Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2004    Accepted Submission(s): 1085 Problem Description Biologists finally invent techniques of repairing DNA that contains segments c

[ACM] hdu 3555 Bomb (数位DP,统计1-N中含有“49”的总数)

Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7187 Accepted Submission(s): 2512 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro

HDU 4833 Best Financing DP

Best Financing Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 120    Accepted Submission(s): 24 Problem Description 小 A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在