// hdu 3664 Permutation Counting 简单dp
//
// 解题思路:
// dp[i][j] 表示最大数为i的E的值为j的排列个数.
// 则对于i+1来说有三种选择:
// 放在该位 dp[i-1][j]
// 与A[i] > i 交换 dp[i-1][j] * j;
// 与A[i] < i 交换 dp[i-1][j-1] * (i - j);
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#define For(x,a,b,c) for (int x = a; x <= b; x += c)
#define Ffor(x,a,b,c) for (int x = a; x >= b; x -= c)
#define cls(x,a) memset(x,a,sizeof(x))
using namespace std;
typedef long long ll;
const int MAX_N = 108;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
ll f[1008][1008];
void init(){
f[0][0] = 1;
f[1][0] = 1;
For(i,2,1000,1){
For(j,0,i,1){
f[i][j] = f[i-1][j];
if (j > 0)
f[i][j] = ((f[i-1][j] * (j + 1)) % MOD + (f[i-1][j-1] * (i - j)) )% MOD;
}
}
}
int main(){
int n,m;
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
init();
while(scanf("%d%d",&n,&m)!=EOF){
printf("%I64d\n",f[n][m]);
}
}
hdu 3664 Permutation Counting 简单dp
最新推荐文章于 2017-03-27 22:14:21 发布