uva 12034
/* 比赛的名次的所有方案数 _________________________________________________________________________________
#include <iostream>
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#define fir first
#define sec second
#define pb(x) push_back(x)
#define mem(A, X) memset(A, X, sizeof A)
#define REP(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define rep(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<long,long> pll;
LL T,n;
const LL mod=10056;
LL f[1000+10];
LL c[1005][1005];
const int maxn=1001;
const int MOD=10056;
void init() {
for(int i = 0; i <= maxn; i++) {
c[i][0] = c[i][i] = 1;
for(int j = 1; j < i; j++)
c[i][j] = (c[i-1][j] + c[i-1][j-1]) % MOD;
}
}
int main()
{
freopen("in.txt","r",stdin);
init();
mem(f,0); f[0]=1;
REP(n,1,1000)
REP(i,1,n) f[n]+=c[n][i]*f[n-i]%mod;
while(cin>>T)
{
REP(kase,1,T)
{
int n;
cin>>n;
cout<<"Case "<<kase<<": "<<f[n]%mod<<endl;
}
}
return 0;
}
/*
note : 运用子问题寻找递推关系。
debug : 组合数初始化的时候,牵扯到取模的时候不能用横向的递推关系,会导致出现0,
optimize:
*/
uva 12034的更多相关文章
- UVa 12034 - Race(递推 + 杨辉三角)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 12034 (递推) Race
题意: 有n个人赛马,名次可能并列,求一共有多少种可能. 分析: 设所求为f(n),假设并列第一名有i个人,则共有C(n, i)种可能,接下来确定后面的名次,共有f(n-1)种可能 所以递推关系为: ...
- UVa 12034 Race (递推+组合数学)
题意:A,B两个人比赛,名次有三种情况(并列第一,AB,BA).输入n,求n个人比赛时最后名次的可能数. 析:本来以为是数学题,排列组合,后来怎么想也不对.原来这是一个递推... 设n个人时答案为f( ...
- UVa 12034 比赛名次(递推)
https://vjudge.net/problem/UVA-12034 题意: A.B两人赛马,最终名次有3种可能:并列第一:A第一B第二:B第一A第二.输入n,求n人赛马时最终名次的可能性的个数除 ...
- Race UVA - 12034(dp+打表)
Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded ...
- UVA 12034 Race
https://vjudge.net/problem/UVA-12034 题意:n个人比赛,有多少种可能的结果 假设i个人中,有j个人是第一名,方案数为C(i,j) 所以ans=Σ C(n,j)* f ...
- UVA 12034 Race (递推神马的)
Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded ...
- UVA 12034 Race(递推)
递推,f[i = i个名次][j = 共有j个人] = 方案数. 对于新加入的第j个人,如果并列之前的某个名次,那么i不变,有i个可供并列的名次选择,这部分是f[i][j-1]*i, 如果增加了一个名 ...
- 紫书 例题 10-14 UVa 12034(组合数+递推)
这道题有点类似动态规划,设答案为f(n) 第一个人有i个人,就有c(n,i)种可能 然后后面有f(n-i)种可能,所以相乘,然后枚举所有可能加起来就ok了. #include<cstdio> ...
随机推荐
- Erlang&RabbitMQ服务安装配置
RabbitMQ是流行的开源消息队列系统,是AMQP(Advanced Message Queuing Protocol高级消息队列协议)的标准实现,用erlang语言开发.RabbitMQ据说具有良 ...
- js拖拽效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ueditor 图片上传功能(.net)
假如下载的net文件 所在工程引用bin文件中的Newtonsoft.Json.dll 在浏览器中运行 `net/controller.ashx`,如果返回 "`{"state&q ...
- rails 常用的验证方法 validates (转)
Agile Web Development with Rails 17.4 validation validate 在save的时候激活validate_on_create ...
- 将list转换为datatable的方法
public static DataTable CopyToDataTable<T>(this IEnumerable<T> array) { var ret = new Da ...
- .net core学习笔记(3)-依赖注入
.net core 中使用了大量的依赖注入,对依赖注入一直是一知半解,总想不透,项目中用的是一个网上的开源框架,从底层到web层都是用的构造函数依赖注入. 然后了在继承ActionFilterAttr ...
- join()方法之我见
JavaScript join() 方法 定义和用法 join() 方法用于把数组中的所有元素放入一个字符串. 元素是通过指定的分隔符进行分隔的. 语法 arrayObject.join(separa ...
- hdu 2088
ps: 超级超级水的一道题....就是格式问题要注意... 除了第一个数据,其他的每个数据都要有个空行比如: 4 1 2 3 4 3 4 //这是空行 1 2 3 4 3 4 //这是空行 代码: ...
- 图片压缩工具optipng/jpegoptim安装
[1]还未实践 #yum install optipng -y [2]已成功 #yum install -y libjpeg libjpeg-devel #wget http://freecode.c ...
- JSP页面组件
一.JSP指令 1.page指令 定义:将关于JSP页面一般设置通知给web容器的属性. 语法:<%@ page attribute_list%> 属性:language;extends; ...