1005 ACM组队安排

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Problem Description
  ACM亚洲区比赛结束,意味着开始备战明年的浙江省大学生程序设计竞赛了!

  杭州电子科技大学ACM集训队也准备开始组队。

  教练想把所有的n个队员组成若干支队伍,原则是每支队伍至少一人,最多三人。

  现在问题来了:如果已知集训队队员的数量n,请你帮教练计算出所有可能的组队方案有多少种。



  特别说明:

  队伍没有编号,即如果有A,B,C三人,{A}{BC}与{BC}{A}是同一种组队情况。
 
Input
输入包含多组测试数据(约1000组),每组数据占一行,包含一个数字n(0<=n<=20),表示ACM集训队的队员人数;n为0,表示输入结束。
 
Output
请输出n个队员所有可能的组队方案数,每组输出占一行。
 
Sample Input
1
2
3
4
5
0
 
Sample Output
1
2
5
14
46
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 25;
const int M = 1005;
const int inf = 1000000007;
const int mod = 2009;
__int64 dp[N][N][N][N],c[N][N];
int main()
{
int i,j,k,l,n,x,y;
__int64 sum;
for(i=0; i<=20; i++)
for(j=0; j<=i; j++)
if(j==0||i==j)
c[i][j]=1;
else
c[i][j]=c[i-1][j]+c[i-1][j-1];
for(i=1; i<=20; i++)
for(l=0; l<=20; l++)
for(k=0; k<=20; k++)
{
j=i-3*l-2*k;
if(j<0||j==0&&k==0&&l==0)
continue;
dp[i][j][k][l]=1;
y=i;
for(x=1; x<=k; x++,y-=2)
dp[i][j][k][l]*=c[y][2];
for(x=1; x<=k; x++)
dp[i][j][k][l]/=x;
for(x=1; x<=l; x++,y-=3)
dp[i][j][k][l]*=c[y][3];
for(x=1; x<=l; x++)
dp[i][j][k][l]/=x;
}
while(scanf("%d",&n)&&n)
{
sum=0;
for(j=0; j<=20; j++)
for(k=0; k<=20; k++)
for(l=0; l<=20; l++)
if(j+2*k+3*l==n)
{
sum+=dp[n][j][k][l];
}
printf("%I64d\n",sum);
}
return 0;
}

总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。

计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排的更多相关文章

  1. hdu 计算机学院大学生程序设计竞赛(2015’11)

    搬砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...

  2. 计算机学院大学生程序设计竞赛(2015’12) 1005 Bitwise Equations

    #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...

  3. 计算机学院大学生程序设计竞赛(2015’12)Study Words

    Study Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. 计算机学院大学生程序设计竞赛(2015’12)Polygon

    Polygon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  5. 计算机学院大学生程序设计竞赛(2015’12)The Country List

    The Country List Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words

    #include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...

  7. 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower

    #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...

  8. 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix

    #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...

  9. 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

    #include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...

随机推荐

  1. 【ITOO 4】WCF中,分布式事务处理

    导读:事务可以确保除非事务性单元内的所有操作都成功完成,否则不会永久更新面向数据的资源.通过将一组相关操作组合为一个要么全部成功要么全部失败的单元,可以简化错误恢复并使应用程序更加可靠.在项目中,就有 ...

  2. 表连接sql执行计划学习

    循环嵌套连接(Nested Loop Join) 合并连接(Merge Join) 哈西匹配(Hash Join) 文章:浅谈SQL Server中的三种物理连接操作 循环嵌套,如果内循环列上有索引, ...

  3. CodeForces 556 --Case of Fake Numbers

    B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. [HNOI2015]实验比较 树形dp+组合数学

    在合并的时候有可以加等于,或者继续用小于, 比如siz[x]和siz[y]合并,小于的区间为max(siz[x],siz[y])<=k<=siz[x]+siz[y], 然后就是合并成多少个 ...

  5. 2016 Multi-University Training Contest 9 solutions BY 金策工业综合大学

    A Poor King Tag: Reversed BFS Preprocessing is needed to calculate answers for all positions (states ...

  6. [NOIP1999] 提高组 洛谷P1016 旅行家的预算

    题目描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能行驶的距离D2.出发点每升汽油价格P和沿 ...

  7. Python基础之 一 文件操作

    文件操作 流程: 1:打开文件,得到文件句柄并赋值给一个变量 2:通过句柄对文件进行操作 3:关闭文件 模式解释 r(读) , w(写) ,a(附加)r+(读写的读), w+(读写的写),a+(读附加 ...

  8. Copy List with Random Pointer (Hash表)

    A linked list is given such that each node contains an additional random pointer which could point t ...

  9. Topcoder 658Div2

    补题风向标——>> 假装题意知道 A:暴力合成一遍了 n=s.size(); m=t.size(); ss+=s; tt+=t; if (ss==tt) or not; B:题意是给定 1 ...

  10. 寒武纪camp Day2

    补题进度:8/10 A(计数+BIT) 题意: 给一个长度为n的数组a[],任意选0<=i<=j<n,将a[i]~a[j]从小到大排序,形成新的数组.问有多少个不同的新数组. N,a ...