# 【2019.8.11上午 慈溪模拟赛 T2】十七公斤重的文明（seventeen）（奇偶性讨论+动态规划）

### 代码

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 150
#define Inc(x,y) ((x+=(y))>=X&&(x-=X))
using namespace std;
int n,m,X;
class EvenSolver//k为偶数
{
private:
int f[N+5][N+5];
I int DP(CI n,CI m)//处理小问题
{
RI i,j,ans=0;memset(f,0,sizeof(f));//清空
for(f[0][0]=1,i=0;i^n;++i) for(j=0;j<=m;++j) Inc(f[i+1][0],f[i][j]),Inc(f[i+1][j+1],f[i][j]);//DP
for(i=0;i<=m;++i) Inc(ans,f[n][i]);return ans;//统计答案
}
public:
I void Solve() {printf("%d",1LL*DP(n+1>>1,m>>1)*DP(n>>1,m>>1)%X);}
}E;
class OddSolver//k为奇数
{
private:
int f[N+5][N+5][N+5];
public:
I void Solve()
{
RI i,j,k,ans=0;f[0][0][0]=1;//初始化
for(i=0;i<(m>>1)+(n+1>>1);++i) for(j=0;j<=(n>>1);++j) for(k=0;k<=m+1;++k)//DP
Inc(f[i+1][0][0],f[i][j][k]),i<(n>>1)&&Inc(f[i+1][j+1][0],f[i][j][k]),//两边都不选，左选右不选
i>=(m>>1)&&Inc(f[i+1][0][k?k+1:0],f[i][j][k]),//左不选右选
i>=(m>>1)&&i<(n>>1)&&Inc(f[i+1][j+1][max(j+2,k+1)],f[i][j][k]);//左右都选
for(j=0;j<=(n>>1);++j) for(k=0;k<=m+1;++k) Inc(ans,f[(m>>1)+(n+1>>1)][j][k]);//统计答案
printf("%d",ans);//输出答案
}
}O;
int main()
{
freopen("seventeen.in","r",stdin),freopen("seventeen.out","w",stdout);
return scanf("%d%d%d",&n,&m,&X),m&1?O.Solve():E.Solve(),0;
}
posted @ 2019-08-13 20:08  TheLostWeak  阅读(...)  评论(...编辑  收藏