Race UVA - 12034(dp+打表)】的更多相关文章

Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded and wandered around, even in their holidays. They passed several months in this way. But everything has an end. A holy person, Munsiji came into their…
题目: Bob wants to hold a race to encourage people to do sports. He has got trouble in choosing the route. There are N houses and N - 1 roads in his village. Each road connects two houses, and all houses are connected together. To make the race more in…
题目描述 现在有一个长度为n的随机排列,求它的最长上升子序列长度的期望. 为了避免精度误差,你只需要输出答案模998244353的余数. 输入 输入只包含一个正整数n.N<=28 输出 输出只包含一个非负整数,表示答案模998244353的余数. 可以证明,答案一定为有理数,设其为a/b(a.b为互质的整数),你输出的整数为x, 则你需要保证0≤x<998244353且a与bx模998244353同余. 样例输入 2 样例输出 499122178 题解 状压dp+打表 套路:对于排列问题,从左…
Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded and wandered around, even in their holidays. They passed several months in this way. But everything has an end. A holy person, Munsiji came into their…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3185 题意: A.B两人赛马,最终名次有3种可能:并列第一:A第一B第二:B第一A第二.输入n(1≤n≤1000),求n人赛马时最终名次的可能性的个数除以10056的余数. 分析: 设答案为f(n).假设第一名有i个人,有C(n,i)种可能性,接下来有f(n-i)种可能性,因此答案…
一开始是想排列组合做的,排列组合感觉确实可以推出公式,但是复杂度嘛.. dp[i][j]表示有i只马,j个名次的方法数,显然j<=i,然后递推公式就很好写了,一只马新加进来要么与任意一个名次的马并行,则加进来后仍有j种名次,且有j个名次可选择,所以新增j*dp[i-1][j]种:要么这匹马插进j-1名次中并变成总共j种名次,所以原来应有j-1种名次,在j-1种名次中有j种插法,所以新增j*dp[i-1][j-1] #include <iostream> #include <stri…
题意: 有n个人赛马,名次可能并列,求一共有多少种可能. 分析: 设所求为f(n),假设并列第一名有i个人,则共有C(n, i)种可能,接下来确定后面的名次,共有f(n-1)种可能 所以递推关系为: #include <cstdio> ; ][maxn+], f[maxn+]; ; void Init() { //递推组合数 ; i <= maxn; ++i) { C[i][] = C[i][i] = ; ; j < i; ++j) C[i][j] = (C[i-][j-] + C…
题意:A,B两个人比赛,名次有三种情况(并列第一,AB,BA).输入n,求n个人比赛时最后名次的可能数. 析:本来以为是数学题,排列组合,后来怎么想也不对.原来这是一个递推... 设n个人时答案为f(n)假设第一名有i(0< i <= n)个人,也就是有C(n, i)种,还剩下f(n-i)种可能,然后就so easy了. f(n) = ΣC(n, i)f(n-i). 代码如下: #include <iostream> #include <cstdio> #include…
https://vjudge.net/problem/UVA-12034 题意:n个人比赛,有多少种可能的结果 假设i个人中,有j个人是第一名,方案数为C(i,j) 所以ans=Σ C(n,j)* f[n-j] #include<cstdio> #define mod 10056 using namespace std; ],C[][]; int main() { ;i<=;i++) C[i][]=; ;i<=;i++) ;j<=i;j++) C[i][j]=(C[i-][j…
递推,f[i = i个名次][j = 共有j个人] = 方案数. 对于新加入的第j个人,如果并列之前的某个名次,那么i不变,有i个可供并列的名次选择,这部分是f[i][j-1]*i, 如果增加了一个名次,那么之前有i-1个名次,i-1个名次之间有i个空,这部分是f[i-1][j-1]*i. /********************************************************* * --------------Tyrannosaurus--------- * * au…