Time Limit: 20 Sec
Memory Limit: 256 MB
http://codeforces.com/contest/553/problem/B
Input
The first line will contain two integers n, k (1 ≤ n ≤ 50, 1 ≤ k ≤ min{1018, l} where l is the length of the Kyoya's list).
Output
Print n space-separated integers, representing the permutation that is the answer for the question.
Sample Input
4 3
Sample Output
1 3 2 4
题意
cycle,就是不在同一个位置的数,会成为一个圈
每个cycle从大到小排序,所有cycle按第一个元素从大到小排序
排序完了以后跟原来的序列不变就是合法
然后让你输出第k大的合法数组
题解:
dp[i] = dp[i - 1] + dp[i - 2]
比如1号位,可以放1
1号位,也可以放2,如果放2
那么考虑2号位
显然不能比2大
那就只能放1了
1号位放3以上的都不行
知道合法种类数有第n个fib数个数之后,构造方法就很显然了
代码
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 2000001 #define mod 1000000007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; /* inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } */ inline ll read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** ll c[100]={1,1,},k; int n,a[100]; main() { for(int i=2;i<100;i++) c[i]=c[i-1]+c[i-2]; cin>>n>>k; for(int i=1;i<=n;) { if (k>c[n-i]) { k-=c[n-i]; a[i]=i+1; a[i+1]=i;i+=2; } else { a[i]=i; i++; } } for(int i=1;i<=n;i++) printf("%d ",a[i]); }