CodeForces 128C Games with Rectangle [组合数学+基础DP]
来源:互联网 发布:萃妮缇 知乎 编辑:程序博客网 时间:2024/06/10 00:23
题意:给你一个N*M大的矩形,作为第一个画好的矩形,每一次你都要在上一次画好的矩形里再选一个不与大矩形接触的子矩形,问你选K次后不同的方案数有几个。
范围: N,M<=1000
解法: 可以发现行与列没有关系,所以问题即转化为线段里选取子线段的问题,用DP[I][J] 转移长度为I的线段里找出J条依次被上一条完全包含(不包括边界)的方案数,然后答案就是DP[N]K]*DP[M][K]
代码:
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<iostream>#include<stdlib.h>#include<set>#include<map>#include<queue>#include<vector>#include<bitset>#pragma comment(linker, "/STACK:1024000000,1024000000")template <class T>bool scanff(T &ret){ //Faster Input char c; int sgn; T bit=0.1; if(c=getchar(),c==EOF) return 0; while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); if(c==' '||c=='\n'){ ret*=sgn; return 1; } while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10; ret*=sgn; return 1;}#define inf 1073741823#define llinf 4611686018427387903LL#define PI acos(-1.0)#define lth (th<<1)#define rth (th<<1|1)#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)#define mem(x,val) memset(x,val,sizeof(x))#define mkp(a,b) make_pair(a,b)#define findx(x) lower_bound(b+1,b+1+bn,x)-b#define pb(x) push_back(x)using namespace std;typedef long long ll;typedef pair<int,int> pii;ll mod=1000000007LL;ll dp[1111][1111];void init(){ dp[0][0]=0; rep(i,1,1000){ dp[i][0]=1; } rep(j,1,1000){ ll sum=0; ll temp=0; rep(i,1,1000){ dp[i][j]=temp; sum=(sum+dp[i-1][j-1])%mod; temp=(temp+sum)%mod; } }}main(){ init(); int n,m,k; scanff(n); scanff(m); scanff(k); printf("%lld\n",(dp[n][k]*dp[m][k])%mod);}
0 0
- CodeForces 128C Games with Rectangle [组合数学+基础DP]
- CodeForces 128C Games with Rectangle 组合数学
- Codeforces 128 C. Games with Rectangle
- codeforces 129E/128C Games with Rectangle
- C. Games with Rectangle CF 128C
- codeforce 128C Games with Rectangle 排列组合
- Codeforces 666C C. Codeword 组合数学+DP
- Codeforces 360C - Levko and Strings 组合数学+DP
- codeforces 559C Gerald and Giant Chess(dp+组合数学)
- Codeforces 559C Gerald and Giant Chess 组合数学 DP
- codeforces 156C Cipher 组合数学 字符串dp
- Codeforces 554C Kyoya and Colored Balls 【dp + 组合数学】
- CodeForces 28 C.Bath Queue(概率DP+组合数学)
- CodeForces 554C 组合数学
- codeforces 294C组合数学)
- Codeforces Round #445 Div1 C:Maximum Element (组合数学+DP)
- Codeforces 300C Beautiful Numbers 【组合数学】
- CodeForces 57 C.Array(组合数学)
- 设计模式-工厂模式
- MAC OS EI Capitan系统文件修改
- hdu acm 3535 AreYouBusy
- Android基础和运行机制
- Linux C hello world
- CodeForces 128C Games with Rectangle [组合数学+基础DP]
- Perl学习笔记(二)
- hdu5137 How Many Maos Does the Guanxi Worth(ACM/ICPC 西安区域赛现场赛)
- ffmpeg使用libx264编码时,为何一直出现x264 [warning]: non-strictly-monotonic PTS?
- poj 1141 Brackets Sequence(区间DP记录路径)
- VS
- eclipse
- shell判断文件夹是否存在
- ios学习之cocoa的大致了解