Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You can
earrange this sequence in many ways. There will be N! different arrangements. You have to calculate
the number of arrangement of first N natural numbers, where in first M (M ≤ N) positions, exactly
K (K ≤ M) numbers are in its initial position.
Example:
For, N = 5, M = 3, K = 2
You should count this arrangement {1, 4, 3, 2, 5}, here in first 3 positions 1 is in 1-st position and
3 in 3-rd position. So exactly 2 of its first 3 are in there initial position.
But you should not count this {1, 2, 3, 4, 5}.
Input
The first line of input is an integer T (T ≤ 1000) that indicates the number of test cases. Next T line
contains 3 integers each, N (1 ≤ N ≤ 1000), M, and K.
Output
For each case, output the case number, followed by the answer modulo 1000000007. Look at the sample
for clarification.
Sample Input
1
5 3 2
Sample Output
Case 1: 12

题意:给你 n,m,k,   表示a[i] = 1,2....,n 经过变换后->  前m个数中只有任意 k个数满足 i = a[i]问你方案数

题解:我们  先在前m个数中任意选k个数是满足不变的  即 C(m,k);

   再枚举后n-m个中有多少个数的位置是不变的,C(n−m,x),这样就有n−k−x个数为乱序排列。

   对于y个数乱序排序,我们考虑dp做法,假设已经 求出 y-1,y-2个数的乱序排序数,那么 dp[y] = (y-1)*(dp[y-1]+dp[y-2]);(详见上一题)

//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = +;
const int M = ;
const int inf = 0x3f3f3f3f;
const ll MOD = ; int n, m, k;
ll dp[N], c[N][N];
void init () {
for (int i = ; i < N; i++) {
c[i][] = c[i][i] = ;
for (int j = ; j < i; j++)
c[i][j] = (c[i-][j-] + c[i-][j]) % MOD;
}
dp[] = ;
dp[] = ;
dp[] = ;
for (ll i = ; i < N; i++)
dp[i] = ((dp[i-] + dp[i-]) % MOD * (i-)) % MOD;
} ll solve () {
ll ans = ;
int t = n - m;
for(int i = ;i <= n-m; i++) ans += (c[t][i]*dp[n-k-i]), ans %= MOD;
return (ans * c[m][k]) % MOD;
}
int main () {
init();
int cas = , T;
scanf("%d", &T);
while(T--) {
scanf("%d%d%d", &n, &m, &k);
printf("Case %d: %lld\n", cas++, solve());
}
return ;
}

代码

UVA 11481 - Arrange the Numbers 数学的更多相关文章

  1. UVA 11481 Arrange the Numbers(组合数学 错位排序)

    题意:长度为n的序列,前m位恰好k位正确排序,求方法数 前m位选k个数正确排,为cm[m][k],剩余m - k个空位,要错排,这m - k个数可能是前m个数中剩下的,也可能来自后面的n - m个数 ...

  2. UVa 11481 Arrange the Numbers (组合数学)

    题意:给定 n,m,k,问你在 1 ~ n 的排列中,前 m 个恰好有 k 个不在自己位置的排列有多少个. 析:枚举 m+1 ~ n 中有多少个恰好在自己位置,这个是C(n-m, i),然后前面选出 ...

  3. UVA 11582 Colossal Fibonacci Numbers(数学)

    Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...

  4. uva 10712 - Count the Numbers(数位dp)

    题目链接:uva 10712 - Count the Numbers 题目大意:给出n,a.b.问说在a到b之间有多少个n. 解题思路:数位dp.dp[i][j][x][y]表示第i位为j的时候.x是 ...

  5. UVA 10539 - Almost Prime Numbers(数论)

    UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...

  6. light oj 1095 - Arrange the Numbers排列组合(错排列)

    1095 - Arrange the Numbers Consider this sequence {1, 2, 3 ... N}, as an initial sequence of first N ...

  7. UVa 11481 (计数) Arrange the Numbers

    居然没有往错排公式那去想,真是太弱了. 先在前m个数中挑出k个位置不变的数,有C(m, k)种方案,然后枚举后面n-m个位置不变的数的个数i,剩下的n-k-i个数就是错排了. 所以这里要递推一个组合数 ...

  8. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  9. UVA 11461 - Square Numbers 数学水题

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

随机推荐

  1. 部分手机不能连PC adb

    http://www.th7.cn/Program/java/201407/232139.shtml 1. 命令行中执行 android update adb [这一步的目的是产生下面第二步的路径和文 ...

  2. android几种定时器机制及区别

    在android中,经常用到的定时器主要有以下几种实现:一.采用Handler与线程的sleep(long )方法二.采用Handler的postDelayed(Runnable, long) 方法三 ...

  3. Oracle ODP.NET连接池

    数据库连接池 连接池是数据库连接的缓存,每当应用程序需要连接数据库时向连接池申请数据库连接,连接池负责具体数据库连接的创建和销毁.连接池中的数据库连接会缓存一段时间,后续的连接请求首先使用缓存中的数据 ...

  4. ExtJS MVC 学习手记3

    在演示应用中,我们已经创建好了viewport,并为之添加了一个菜单树.但也仅仅是这样,点击树或应用的其他地方获得不到任何响应.这个演示应用还是一个死的应用. 接下来,我们让这个应用活起来. 首先,给 ...

  5. exception -----> Typedefs & Classes

    #include <exception> Typedefs exception_ptr 一种类型,描述了一个指向异常的指针 terminate_handler 一种类型,描述了一个适合作为 ...

  6. P3408: [Usaco2009 Oct]Heat Wave 热浪

    水题,裸的最短路. ; type link=^node; node=record t,d:longint; f:link; end; var n,m,s,i,j,u,v,w,max:longint; ...

  7. self.a 和 _a 的区别

    在OC中我们可以通过指令@property定义属性. OC对属性封装了许多方法,同时也会自动实现一些方法,相比实例变量,感觉更加面向对象些. 一般定义属性的方法如下,在Class Test中定义属性i ...

  8. 四则运算2扩展---c++

    题目:让程序能接受用户输入答案,并判定对错.最后给出总共对/错 的数量. 一.设计思想 1.存储用户输入答案,与正确答案比较得出总共对错数量. 二.源程序代码 #include<iostream ...

  9. 【CentOS 6.5】 U盘安装以及桌面空白问题

    在研华ARK-5260上安装CentOS 6.5 下载CentOS-6.5-x86_64-bin-DVD1.iso 附上百度网盘下载地址:http://pan.baidu.com/s/1eQf1Eeu ...

  10. 【BZOJ】【1037】【ZJOI2008】生日聚会party

    DP orz iwtwiioi 这种题居然是DP……原来统计方案数是可以用动态规划来做的啊= =用一些变量来维护一些信息,保证方案可行性/合法性 人太弱实在是有些忧伤…… /************* ...