您的位置:首页 > 其它

hdu 3664 Permutation Counting 简单dp

2015-10-16 10:44 375 查看
//	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
[m]);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息