codeforces #309 div2 分类: codeforces 2015-06-26 20:11 21人阅读 评论(0) 收藏
显然是个数学题,对于第
可以视为将第
另外
显然也是个数学题,每个置换环用最大表示法表示,而置换环又按从小到大排列。
所以只会出现长度为
令
这样我们就可以知道后面的序列还有多少种方案可行,
令
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
const int maxn = 1005, Mod = 1e9+7;
int n, c[maxn], tot, max;
int g[maxn][maxn];
long long ans = 1;
int main()
{
#ifndef ONLINE_JUDGE
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
#endif
std::cin >> n;
for(int i = 1; i <= n; i++)
{
std::cin >> c[i], tot += c[i];
max = std::max(max, c[i]);
}
for(int i = 0; i <= tot; i++)
g[i][0] = 1;
for(int i = 1; i <= tot; i++)
for(int j = 1; j < max; j++)
g[i][j] = (g[i-1][j-1]+g[i-1][j])%Mod;
for(int i = 1, sum = 0; i <= n; i++)
{
sum += c[i];
ans *= g[sum-1][c[i]-1];
ans %= Mod;
}
std::cout << ans;
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<iostream>
#include<algorithm>
const int maxn = 55;
long long f[maxn];
int n; long long k;
int main()
{
#ifndef ONLINE_JUDGE
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
#endif
std::cin >> n >> k;
f[1] = f[2] = 1;
for(int i = 3; i <= n; i++)
f[i] = f[i-1] + f[i-2];
for(int i = 1; i <= n; i++)
{
if(k > f[n-i+1] && i < n)
{
k -= f[n-i+1];
std::cout << i+1 << ' ';
std::cout << i++ << ' ';
}
else
std::cout << i << ' ';
}
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。