Codeforces 367E
来源:互联网 发布:禁毒网络知识竞赛 编辑:程序博客网 时间:2024/06/16 10:28
dp[i][j][k]表示前i个数,出现j个左边界k个右边界情况总数
1. 左边界
2. 右边界
3. 左边界和右边界
4. 什么都不是
#include<cstdio>#include<iostream>#include<cstring>using namespace std;typedef __int64 LL;const int mod=1e9+7;LL jie[400];void init(){ jie[0]=1; int n=350; for(int i=1;i<=n;i++){ jie[i]=(LL)jie[i-1]*i%mod; }}void fun(LL x,LL &y){ y+=x; if(y>=mod)y-=mod;}LL dp[2][400][400];int main(){ #ifdef DouBi freopen("in.cpp","r",stdin); #endif // DouBi init(); int n,m,id; while(scanf("%d%d%d",&n,&m,&id)!=EOF){ if(n>m){ printf("0\n");continue; } memset(dp,0,sizeof(dp)); dp[0][0][0]=1; for(int i=1;i<=m;i++){ int x=i%2; if(i<id)dp[x][0][0]=1; else dp[x][0][0]=0; for(int j=1;j<=min(n,i);j++){ LL y=0; if(i!=id){ fun(dp[x^1][j][0],y); fun(dp[x^1][j-1][0],y); } else { fun(dp[x^1][j-1][0],y); } dp[x][j][0]=y; for(int j1=1;j1<=j;j1++){ y=0; if(i!=id){ fun(dp[x^1][j][j1],y); fun(dp[x^1][j-1][j1],y); fun(dp[x^1][j][j1-1],y); fun(dp[x^1][j-1][j1-1],y); } else { fun(dp[x^1][j-1][j1],y); fun(dp[x^1][j-1][j1-1],y); } dp[x][j][j1]=y; } } //printf("%d:%d\n",i,dp[x][n][n]); //if(i>=id)fun(dp[x][n][n],ans); } int ans=(LL)dp[m%2][n][n]*jie[n]%mod; //printf("%djie\n",jie[n]); printf("%d\n",ans); } return 0;}
0 0
- Codeforces 367E
- Codeforces 367E Sereja and Intervals DP
- Codeforces Round #367 (Div. 2)E
- Codeforces Round #367 (Div. 2)E
- Codeforces Round #367 (Div. 2) A~E
- codeforces 163E e-Government
- 【Codeforces 163E】E-Government
- Codeforces 78E Evacuation
- 【dp】codeforces 83E
- Codeforces 124 E
- Codeforces 231E
- Codeforces 231E - Cactus
- Codeforces #163 Div2 E
- codeForces 35E
- Codeforces 35E
- Playlist codeforces 268E
- Codeforces 148E(Porcelain)
- codeforces round#177 E
- Android Studio2.2新功能
- nginx 安装ab小工具方法
- 代码签名探析
- 循环得到一条记录中每个字段里的数据
- Jenkins 安装
- Codeforces 367E
- Bitmap,byte[],Drawable,InputStream相互转化工具类
- spring框架的7个模块
- 显示某个目录下的所有文件和文件夹
- MySQL的存储引擎
- 网页爬虫技术浅析
- Android 随手记:Android开发在一个Activity中关闭另一个Activity
- AndroidManifest之内容相关属性
- 块级元素、内联元素之间的转换,以及高度适应