标签:输出 fine stack ons 方案 top type bit main
输入包括一行,包含两个整数n和k(k < n ≤ 1000)
输出满足条件的排列数,答案对2017取模。
5 2
66
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define ls i<<1 #define rs ls | 1 #define mid ((ll+rr)>>1) #define pii pair<int,int> #define MP make_pair typedef long long LL; const long long INF = 1e18+1LL; const double Pi = acos(-1.0); const int N = 1e3+10, M = 1e3+20, mod = 2017,inf = 2e9; int n,k; LL dp[N][N]; int main(){ scanf("%d%d",&n,&k); dp[1][0] = 1; for(int i = 1; i <= n; ++i) { for(int j = 0; j < i; ++j) { dp[i+1][j] += dp[i][j]*(j+1); dp[i+1][j] %= mod; dp[i+1][j+1] += dp[i][j]*(i-1-j+1); dp[i+1][j+1] %= mod; } } printf("%lld\n",dp[n][k]); return 0; }
标签:输出 fine stack ons 方案 top type bit main
原文地址:http://www.cnblogs.com/zxhl/p/7040603.html