# hdu 3664 dp

<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">Permutation Counting</span>
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1501    Accepted Submission(s): 764

Problem Description
Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of elements where ai > i. For example, the E-value of permutation {1, 3, 2, 4} is 1, while the E-value of {4, 3, 2, 1} is 2. You are requested to find how many permutations of {1, 2, …, N} whose E-value is exactly k.

Input
There are several test cases, and one line for each case, which contains two integers, N and k. (1 <= N <= 1000, 0 <= k <= N).

Output
Output one line for each case. For the answer may be quite huge, you need to output the answer module 1,000,000,007.

Sample Input
3 0 3 1

Sample Output
1 4
Hint
There is only one permutation with E-value 0: {1,2,3}, and there are four permutations with E-value 1: {1,3,2}, {2,1,3}, {3,1,2}, {3,2,1}

Source

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define F first
#define S second
#define PI acos(-1.0)
#define E  exp(1.0)
#define INF 0xFFFFFFF
#define MAX -INF
#define len(a) (__int64)strlen(a)
#define mem0(a) (memset(a,0,sizeof(a)))
#define mem1(a) (memset(a,-1,sizeof(a)))
using namespace std;
__int64 gcd(__int64 a, __int64 b) {
return b ? gcd(b, a % b) : a;
}
__int64 lcm(__int64 a, __int64 b) {
return a / gcd(a, b) * b;
}
__int64 max(__int64 a, __int64 b) {
return a > b ? a : b;
}
__int64 min(__int64 a, __int64 b) {
return a < b ? a : b;
}
long long dp[1010][1010];
const long long mod = 1000000007;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
int n, k;
for (int i = 1; i <= 1000; i++) {
dp[i][0] = 1;
for (int j = 1; j < i; j++)
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j] * j
+ dp[i - 1][j - 1] * (i - j)) % mod;
}
while (scanf("%d%d", &n, &k) != EOF) {
printf("%I64d\n", dp[n][k]);
}
return 0;
}


• 本文已收录于以下专栏：

## hdu 3664Permutation Counting(简单dp)

Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...
• opm777
• 2013年11月01日 15:09
• 1022

## HDU 3664 Permutation Counting(DP)

Description Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the am...

## HDU 3664 Permutation Counting （DP）

Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...

## HDU 3664 Permutation Counting (DP)

Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot...

## HDU DP 题集

• 2013年04月24日 18:31
• 724KB
• 下载

## ZOJ Problem Set - 3664 Split the Rectangle

The 2012 ACM-ICPC Asia Changchun Regional Contest-J 题目大一就是去掉某一些使得两个点在同一矩形内，然后问有还剩多少矩形。 实际就...
• KQZXCMH
• 2012年10月16日 16:41
• 601

## poj-3664

#include #include #include using namespace std; #define COW_NUM 50000 class cow_vote {...
• fyfcauc
• 2014年06月26日 15:34
• 330

举报原因： 您举报文章：hdu 3664 dp 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)