CodeForces 37 D.Lesson Timetable(组合数学+dp)
来源:互联网 发布:二手手机回收软件 编辑:程序博客网 时间:2024/05/18 03:34
Description
有
Input
第一行一个整数
Output
输出方案数,结果模
Sample Input
3
1 1 1
1 2 3
Sample Output
36
Solution
首先不考虑人的编号,用
枚举第
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;typedef pair<int,int>P;const int INF=0x3f3f3f3f,maxn=1005;#define mod 1000000007int dp[maxn][maxn],fact[maxn],inv[maxn];void init(int n=1000){ fact[0]=1; for(int i=1;i<=n;i++)fact[i]=(ll)i*fact[i-1]%mod; inv[1]=1; for(int i=2;i<=n;i++)inv[i]=mod-(ll)(mod/i)*inv[mod%i]%mod; inv[0]=1; for(int i=1;i<=n;i++)inv[i]=(ll)inv[i-1]*inv[i]%mod;}int C(int n,int m){ return (ll)fact[n]*inv[m]%mod*inv[n-m]%mod;}int m,x[maxn],y[maxn],s[maxn];int main(){ init(); while(~scanf("%d",&m)) { s[0]=0; for(int i=1;i<=m;i++) { scanf("%d",&x[i]); s[i]=s[i-1]+x[i]; } for(int i=1;i<=m;i++)scanf("%d",&y[i]); memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=1;i<=m;i++) for(int j=0;j<=s[i];j++) for(int k=0;k<=min(j,y[i]);k++) { dp[i][j]+=(ll)dp[i-1][j-k]*C(s[i]-(j-k),k)%mod; if(dp[i][j]>=mod)dp[i][j]-=mod; } int ans=(ll)dp[m][s[m]]*fact[s[m]]%mod; for(int i=1;i<=m;i++)ans=(ll)ans*inv[x[i]]%mod; printf("%d\n",ans); } return 0;}
阅读全文
0 0
- CodeForces 37 D.Lesson Timetable(组合数学+dp)
- CodeForces 233 D.Table(dp+组合数学)
- Codeforces 466D Increase Sequence(dp+组合数学)
- Codeforces 466D Increase Sequence(dp+组合数学)
- CodeForces 26 D.Tickets(组合数学)
- codeforces 500D - New Year Santa Network (树形DP+组合数学)
- Codeforces-785D (组合数学)
- [Codeforces37D]Lesson Timetable
- Codeforces Gym 100589F Count Ways(DP+组合数学)
- CodeForces 15 E.Triangles(组合数学+dp)
- CodeForces 28 C.Bath Queue(概率DP+组合数学)
- Codeforces 615D Multipliers 【组合数学】
- codeforces 900D(组合数学+剪枝)
- Codeforces-830D Singer House(组合数+dp)
- hdu4945(dp+组合数学)
- Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)
- codeforces 380D. Sereja and Cinema(#223div1 组合数学)
- Codeforces Round #369 (Div. 2) D. Directed Roads (dfs+组合数学 图论)
- 数据结构实验之排序四:寻找大富翁
- vsCode 插件离线安装(在应用商店中无法直接安装)
- 基于OpenCV3.2+VS2013双目测距
- SSL P1643 最小乘车费用 题目
- springboot项目浏览器报错:There was an unexpected error (type=Not Found, status=404).
- CodeForces 37 D.Lesson Timetable(组合数学+dp)
- springmvc学习二
- ftp服务器搭建与访问
- Root of AVL Tree
- 两台不同window7机器上的oralce,实例之间相互拷贝的方式(EXPDP和IMPDP数据泵)
- USB驱动程序之USB设备驱动程序2鼠标用作键盘学习笔记
- Sun的逆向之路(一)——元气骑士的内购破解
- java12周(2)第一题
- 计算1000到1的平方根,并将结果保存至二进制文件root.dat.