HDU4301 Divide Chocolate

There are several ways to give you t group data 2*a pieces of chocolate are divided into k pieces

The code for this question is not difficult to understand if you look at the solution, that is, let each state be transferred from the previous state, using the dp idea, do more questions, and then you can see how to respond to this kind of question.

f[i][j][0/1] i means which row is j means divided into several points 0/1 means whether the i-th row is connected

#include<bits/stdc++.h>
using namespace std;
const int mo=100000007;
int f[1100][2200][4]= {0};
int main()
{
f[1][2][0]=1;
f[1][1][1]=1;
for(int i=1; i<=1000; i++)
{
for(int j=1; j<=2*i; j++)
{
// cout<<i<<" "<<j<<':'<<f[i][j][0]<<' '<<f[i][j][1]<<endl;
f[i+1][j][0]+=f[i][j][0]%mo;
f [i + 1 ] [j] [ 1 ]+ = (f [i] [j] [ 1 ]+ 2 *f [i] [j] [ 0 ])% mo;
f [i + 1 ] [j+ 1 ] [ 0 ]+ = ( 2 *f [i] [j] [ 1 ]+ 2 *f [i] [j] [ 0 ])% mo;
f [i + 1 ] [j+ 1 ] [ 1 ]+ = (f [i] [j] [ 1 ]+ f [i] [j] [ 0 ])% mo;
f [i + 1 ] [j+ 2 ] [ 0 ]+ = (f [i] [j] [ 0 ]+ f [i] [j] [ 1 ])% mo;
}
}
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d %d",&a,&b);
printf("%d\n",(f[a][b][0]+f[a][b][1])%mo);
}
return 0;
}

Do more questions to better understand dp thinking.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325224049&siteId=291194637