CodeForces 630 G. Challenge Pennants(组合数学)
2016-03-20 09:47
357 查看
Challenge Pennants
Crawling in process...
Crawling failed
Time Limit:500MS
Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
CodeForces 630G
Description
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature"
pennant on his table.
Because of the limited budget of the new reward system only
5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of
the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are
n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 500) — the number of tables in the IT company.
Output
Output one integer — the amount of ways to place the pennants on
n tables.
Sample Input
Input
Output
24
题意:有两种不同的旗子,分别是5个,3个,分给n个人,求有多少不同的分法!
(1) x(x>=1&&x<=5) 面旗子分给不同人数的方法 5 4 3 2 1————》》1 4 6 4 1
(3)y(y>=1&&y<=3)面旗子分给不同人数的方法 3 2 1————》》1 2 1
从n个人中选出x(x从1到5)个人C(n,x);->a=C(n,5)+4*C(n,4)+6*C(n,3)+4*C(n,2)+C(n,1);
从n个人中选出y(x从1到3)个人C(n,y);-> b=C(n,3)+2*C(n,2)+C(n,1);
ans=a*b;
AC-code
#include<stdio.h>
#include<math.h>
long long C(long long n,int x )
{
long long temp=1;
for(int i=1;i<=x;i++)
temp=temp*(n-i+1)/i;
return temp;
}
int main()
{
long long n;
while(scanf("%lld",&n)!=EOF)
{
long long a,b;
a=C(n,5)+4*C(n,4)+6*C(n,3)+4*C(n,2)+C(n,1);
b=C(n,3)+2*C(n,2)+C(n,1);
printf("%lld\n",a*b);
}
return 0;
}
Crawling in process...
Crawling failed
Time Limit:500MS
Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
CodeForces 630G
Description
Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature"
pennant on his table.
Because of the limited budget of the new reward system only
5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of
the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are
n tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
Input
The only line of the input contains one integer n (1 ≤ n ≤ 500) — the number of tables in the IT company.
Output
Output one integer — the amount of ways to place the pennants on
n tables.
Sample Input
Input
2
Output
24
题意:有两种不同的旗子,分别是5个,3个,分给n个人,求有多少不同的分法!
(1) x(x>=1&&x<=5) 面旗子分给不同人数的方法 5 4 3 2 1————》》1 4 6 4 1
(3)y(y>=1&&y<=3)面旗子分给不同人数的方法 3 2 1————》》1 2 1
从n个人中选出x(x从1到5)个人C(n,x);->a=C(n,5)+4*C(n,4)+6*C(n,3)+4*C(n,2)+C(n,1);
从n个人中选出y(x从1到3)个人C(n,y);-> b=C(n,3)+2*C(n,2)+C(n,1);
ans=a*b;
AC-code
#include<stdio.h>
#include<math.h>
long long C(long long n,int x )
{
long long temp=1;
for(int i=1;i<=x;i++)
temp=temp*(n-i+1)/i;
return temp;
}
int main()
{
long long n;
while(scanf("%lld",&n)!=EOF)
{
long long a,b;
a=C(n,5)+4*C(n,4)+6*C(n,3)+4*C(n,2)+C(n,1);
b=C(n,3)+2*C(n,2)+C(n,1);
printf("%lld\n",a*b);
}
return 0;
}
相关文章推荐
- 初学ACM - 组合数学基础题目PKU 1833
- 【组合数学】卡塔兰数
- 组合数学学习之排列、组合、圆周排列实现
- 卡特兰数(Catalan)及应用
- POJ1833-排列
- 1139: 出栈序列统计
- POJ 3292.Semi-prime H-numbers
- Java 产生随机的一组排列
- Catalan数
- poj_1942
- poj_1850
- HDU 4832 Chess (动态规划+组合数学)
- hdoj_2049 不容易系列之(4)——考新郎
- hdoj_2048 神、上帝以及老天爷
- hdoj_2047 阿牛的EOF牛肉串
- hdoj_2046 骨牌铺方格
- hdoj_2045 不容易系列之(3)—— LELE的RPG难题
- hdoj_2044 一只小蜜蜂...
- hdoj_2042 不容易系列之二
- hdoj_2041 超级楼梯