uva 11481 - Arrange the Numbers(计数问题)
2014-05-25 23:13
441 查看
题目链接:uva
11481 - Arrange the Numbers
题目大意:给出n,m和k,表示有一个序列,由1~n组成,有序,现在将这个序列重排,问有多少种重排序列满足:前m个中恰好有k个的位置不变(即i=pos[i])。解题思路:首先c=C(km)为前m个数选中k个位置保持不变,然后枚举后n-m个中有多少个数的位置是不变的,C(in−m),这样就有n−k−i个数为乱序排列。解法和uva10497一样。
#include <cstdio> #include <cstring> typedef long long ll; const int N = 1005; const ll MOD = 1000000007; int n, m, k; ll dp , c ; void init () { memset(c, 0, sizeof(c)); for (int i = 0; i < N; i++) { c[i][0] = c[i][i] = 1; for (int j = 1; j < i; j++) c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD; } dp[0] = 1; dp[1] = 0; for (ll i = 2; i < N; i++) dp[i] = ((dp[i-1] + dp[i-2]) % MOD * (i-1)) % MOD; } ll solve () { ll ans = 0; int t = n - m; for (int i = 0; i <= t; i++) ans = (ans + c[t][i] * dp[n-k-i]) % MOD; return (ans * c[m][k]) % MOD; } int main () { init(); int cas; scanf("%d", &cas); for (int i = 1; i <= cas; i++) { scanf("%d%d%d", &n, &m, &k); printf("Case %d: %lld\n", i, solve()); } return 0; }
相关文章推荐
- UVa:11481 Arrange the Numbers
- uva11481 Arrange the Numbers(错位排列)
- uva 11481 Arrange the Numbers
- uva11481 - Arrange the Numbers N个数前M个错排
- UVA - 11481 Arrange the Numbers
- UVA 11481 Arrange the Numbers (容斥)
- Light OJ 1095 Arrange the Numbers(计数)
- UVa 11481 Arrange the Number(容斥原理)
- HDU1492-The number of divisors(约数) about Humble Numbers-数论(计数问题)
- UVa 11481 (计数) Arrange the Numbers
- UVA 12508 - Triangles in the Grid(计数问题)
- UVA 10085 The most distant state(八数码问题)
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
- uva 10328 - Coin Toss(计数问题)
- Uva 101:The Blocks Problem(木块问题)
- uva 11471 Arrange the Tiles (DP)
- UVA 100 - The 3n+1 problem (3n+1 问题)
- UVA 100 && HDU 1032 The 3n+1问题 (扑街题)
- PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)
- 694 - The Collatz Sequence---关于goto语句的一些反思(还有uva的Runtime Error问题的解决)