hdu 新生晚会
每组数据包含两个整数N(来报名的人数,1<=N<=30),M(节目需要的人数0<=M<=30)
3 2
5 3
4 4
3 6
8 0
10
1
0
1
刚开始的思路
二项式系数C(n, k)满足下面的要求:
C(n, k) = C(n − 1, k − 1) + C(n − 1, k) for all 0 < k < n.
#include <stdio.h>
#include <iostream>
using namespace std;
int zuhe(int n,int k)
{
int *result = new int[n];
for(int i=;i<=n;i++)
{
result[i] = ;
for(int j=i-;j>=;j--)
{
result[j] = result[j-]+result[j];
}
result[] = ;
}
return result[k];
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d%d",&a,&b);
if(b>a)
{
printf("0\n");
continue;
}
printf("%d\n",zuhe(a,b));
}
return ;
}
可以这样:
#include<iostream>
using namespace std;
int c[][];
int main()
{
int i,j;
for(i=;i<;i++)
{c[i][]=;c[i][]=i;}
for(i=;i<;i++)
for(j=;j<=i;j++)
c[i][j]=c[i-][j]+c[i-][j-];
int t,n,m;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d%d",&n,&m);
printf("%d\n",c[n][m]);
}
}
return ;
}
之后通过了解:
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
int m,n,t;
long long sum;
cin>>t;
while(t--)
{
cin>>n>>m;
sum=;
for(int i=;i<=m;i++)
{
sum*=n--;
sum/=i;
}
printf("%lld\n",sum);
}
return ;
}
hdu 新生晚会的更多相关文章
- HDOJ(HDU) 2519 新生晚会(组合公式)
Problem Description 开学了,杭电又迎来了好多新生.ACMer想为新生准备一个节目.来报名要表演节目的人很多,多达N个,但是只需要从这N个人中选M个就够了,一共有多少种选择方法? I ...
- hdu 2519 新生晚会 排列组合
通过阶段性计算减少一次性的大值计算 #include <stdio.h> int main() { int t, a, b, i; __int64 c; scanf("%d&qu ...
- hdu 2519 新生晚会 (求排列组合时容易溢出)
#include<stdio.h> #include<algorithm> using namespace std; void cal(int n,int m) { ; m=m ...
- HDU2519:新生晚会
Problem Description 开学了,杭电又迎来了好多新生.ACMer想为新生准备一个节目.来报名要表演节目的人很多,多达N个,但是只需要从这N个人中选M个就够了,一共有多少种选择方法? ...
- POJ 2519
又是一个水题?? 不过还是弄是很久... 在蒟蒻的路上越走越远 , 好了讲题 新生晚会 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- 2017ACM总结
首先对自己表示强烈的谴责, 这个时间应该是打cf的时间, 没有想到我又秀到了自己, 放弃了CF, 23333, 菜鸡wxk. 高中刚毕业的时候,听大学生们跪求老师不要给挂科,当时想的是,哇上了大学就不 ...
- HDU 17新生赛 身份证验证【模拟】
身份证验证 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 17新生赛 正品的概率【数论-概率论】
正品的概率 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 2048 神、上帝以及老天爷(错排)
神.上帝以及老天爷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
随机推荐
- 返璞归真 asp.net mvc (10) - asp.net mvc 4.0 新特性之 Web API
原文:返璞归真 asp.net mvc (10) - asp.net mvc 4.0 新特性之 Web API [索引页][源码下载] 返璞归真 asp.net mvc (10) - asp.net ...
- [LeetCode257]Binary Tree Paths
题目: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree ...
- Windows下效率必备软件
AutoHotKey: 神器!神器!神器!当然也得看使用者咯(^__^) 嘻嘻…… Listary: 本地搜索神器,当然还有别的作用,More&More. Launchy : 快速启动安装的应 ...
- 交换A与B值的四种方法
在网上看到了这样一道面试题,"int A=5,int B=2,怎样交换A与B的值",或许这是一道简单到不能再简单的题,但能作为一道面试题,肯定有其独特之处 大多数人会通过定义第三个 ...
- Myeclipse 10/2014 配置插件(svn、maven、properties、velocity)方法
一.构造SVN具体说明 什么是SVN? 管理软件开发过程中的版本控制工具. 以下会以两种方式来介绍怎么安装svn,myeclipse安装SVN插件步骤.以myeclipse 2014为例,第一种是最常 ...
- win7开机直接进入系统系统桌面
在开始搜索栏输入:netplwiz 选中admin用户(也就是你登录的用户名),然后在把上面的勾去掉,点应用,会提示输入用户名和密码,输二次,是一样的密码,如果没设密码,就不用输直接应用,确定就O ...
- 用DOS命令获取文件列表
其实就是两个命令:dir 跟 tree 在C:盘根目录下生成了一个名为“filelist.txt”的文本文件,该文件中即包含D:盘的文件夹列表. dir d:\ >c:\filelist.txt ...
- 【夯实基础】javakeywordsynchronized 详细说明
尊重版权:http://www.cnblogs.com/GnagWang/archive/2011/02/27/1966606.html Java语言的keyword.当它用来修饰一个方法或者一个代码 ...
- android代码集EditText只要输入号码、信
如何设置EditText,因此,只有某些数字或字母可以进入它? 一.建立EditText,只要输入号码: 办法1:直接生成DigitsKeyListener了. et_1.setKeyListe ...
- js 性能优化整理之 缓存变量
简单的常见的操作:假设每个便签添加一个 属性 -webkit-animation-delay:0.1s 递增操作::通过for循环添加 <ul id="uls"> ...