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]); } }
相关文章推荐
- 构造回文串(简单DP)
- 最长滑雪路(简单DP)
- 和最大的子序列(简单dp)
- POJ 3176 : Triangle - 水DP
- Poj 2392 多重背包变形(模板)
- 最大子矩阵哦!
- HDU -- 2084 数塔(简单DP)
- HDU - 1176 免费馅饼 (简单DP)
- hdu-1081 To The Max (最大子矩阵和)
- 最长上升子序列 最长公共子序列 最长公共子串 数字三角形 等简单DP以及变形
- poj2385
- 哈理工OJ 1186 青蛙过河 (DP问题)
- URAL 1114 Boxes(简单dp)
- URAL 1036 Lucky Tickets(基础dp)
- 地宫取宝 dfs 记忆化搜索 简单dp
- NYOJ 1204 魔法少女 简单DP
- POJ 3176-Cow Bowling/POJ 1163-The Triangle(简单DP-数塔)
- NYOJ-171-聪明的kk(第三届河南省程序设计大赛D题(简单dp))
- FJNU第二十届低年级程序设计竞赛(正式赛)-Problem C-汪老司机(简单DP)
- 51nod 1002 数塔取数问题(简单DP)