CF 553A 组合DP
http://codeforces.com/problemset/problem/553/A
2 seconds
256 megabytes
standard input
standard output
Kyoya Ootori has a bag with n colored balls that are colored with k different
colors. The colors are labeled from 1 to k.
Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color ibefore
drawing the last ball of color i + 1 for all i from 1 to k - 1.
Now he wonders how many different ways this can happen.
The first line of input will have one integer k (1 ≤ k ≤ 1000)
the number of colors.
Then, k lines will follow. The i-th
line will contain ci,
the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000.
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007.
3
2
2
1
3
4
1
2
3
4
1680
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
1 2 1 2 3
1 1 2 2 3
2 1 1 2 3
/**
CF 553A 组合DP
题目大意:在一个口袋里有n种颜色的小球,每一个小球有ai个,如今从口袋里依次取出小球,要求第i种颜色的最后一个球要在第i+1种颜色的最后一个小球的前面被拿出
问有多少种取法?
解题思路:考虑第i种球最后一个球取出来之前前i-1种球必须已经安排好了,那么对于第i种球的ai-1个球仅仅需插入sum[i]之间就可以,故dp[i]=dp[i-1]*c[sum[i]-1][a[i01]];
*/
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int maxn=1200;
LL c[maxn][maxn],dp[maxn],a[maxn];
int n;
void init()
{
c[0][0]=1;
for(int i=1;i<1110;i++)
{
c[i][0]=c[i][1]=1;
for(int j=1;j<=i;j++)
{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
}
/*for(int i=1;i<=10;i++)
{
for(int j=0;j<=i;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}*/
}
int main()
{
init();
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
int sum=0;
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=1;i<=n;i++)
{
sum+=a[i];
dp[i]=(dp[i-1]*c[sum-1][a[i]-1])%mod;
}
printf("%lld\n",dp[n]);
}
return 0;
}
CF 553A 组合DP的更多相关文章
- CF 445A 简单DP
今天早上找一道题的bug,还是找不出来,下午刷了几道水题,晚上准备回家的事, 然后本来想打CF的,一看,数学场,不打了. 这道题的题意: 给出一个序列,每次你可以从这个序列里面选择一个数ak,删除,然 ...
- HDU 4632 CF 245H 区间DP(回文)
先说HDU 4632这道题,因为比较简单,题意就是给你一个字符串,然后给你一个区间,叫你输出区间内所有的回文子序列,注意是回文子序列,不是回文字串. 用dp[i][j]表示区间[i,j]内的回文子序列 ...
- CF 219D 树形DP
CF 219D [题目链接]CF 219D [题目类型]树形DP &题意: 给一个n节点的有向无环图,要找一个这样的点:该点到其它n-1要逆转的道路最少,(边<u,v>,如果v要到 ...
- [Bzoj3193][JLOI2013]地形生成 (排列组合 + DP)
3193: [JLOI2013]地形生成 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 459 Solved: 223[Submit][Status ...
- CF 335B. Palindrome(DP)
题目链接 挺好玩的一个题,1Y... #include <cstdio> #include <cstring> #include <iostream> using ...
- acdream 1412 2-3Trees (组合+DP)
题意:2-3树的每个结点(除了叶子外)有2或3个孩子(分支),假设是一个满2-3树,那么给出叶子的数量,求这样的树有多少棵.(注:有2个孩子的结点视为相同,有3个孩子的结点视为相同,比如倒数第2层有4 ...
- cf 148D 概率DP
题意:原来袋子里有w只白鼠和b只黑鼠龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老师谁就赢.王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来.每次抓老鼠和跑出来的老鼠都是随机的.如果两个人都没 ...
- HDU4532(组合DP)
题目:安排座位 解析:http://www.douban.com/note/269136472/ #include <iostream> #include <string.h> ...
- AGC 001E.BBQ Hard(组合 DP)
题目链接 \(Description\) 给定长为\(n\)的两个数组\(a,b\),求\[\sum_{i=1}^n\sum_{j=i+1}^n\binom{a_i+a_j+b_i+b_j}{a_i+ ...
随机推荐
- SRM 582 Div II Level Two SpaceWarDiv2
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> # ...
- 向服务器写入错误日志-log
/// <summary> /// 写日志,方便测试(看网站需求,也可以改成把记录存入数据库) /// </summary> /// <param name=" ...
- NM_CUSTOMDRAW 消息
When the control first starts to paint itself, in response to a WM_PAINT, you receive a NM_CUSTOMDRA ...
- Solarized Colorscheme for IntelliJ IDEA
Solarized Colorscheme for IntelliJ IDEA Original Solarized color scheme developed by Ethan Schoonove ...
- df -h统计的信息与du -sh不一致的原因(转)
有时候会遇到这样的问题:df -h统计一个目录,显示有约100M可用空间,使用了5G:而用du -sh统计该目录下的文件大小,却发现总共才占用了1G.也就是说,二者统计结果差距巨大. 例如: 1.df ...
- CTreeCtrl结点拖动实现(与后台联动)
原帖及讨论:http://bbs.bccn.net/thread-211413-1-1.html 效果描述:鼠标点击并拖动某一结点可以把它以动到其他结点下.原理:把一个结点机器下面的所有结点在需要释放 ...
- Shell printf 命令
Shell printf 命令 printf 命令模仿 C 程序库(library)里的 printf() 程序. 标准所定义,因此使用printf的脚本比使用echo移植性好. printf 使用引 ...
- hdu1569find the safest road(floyd变形求最大安全值)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- cocos2dx触屏响应(单点触摸)CCTouchBegan,CCTouchMove,CCTouchEnd
今天白白跟大家分享一下cocos2dx单点触摸经验. cocos2dx触摸CCTouch类的单点触摸有四个函数CCTouchBegan,CCTouchMove,CCTouchEnd,CCTouchCa ...
- 应用程序初始化正常(0xc015002)失败解决方法
VS2005 sidebyside manifest error Microsoft.VC80.MFC Microsoft.VC80.CRT Microsoft.VC80.MFCLOC msvcr80 ...