题意:Fi-binary number是二进制位中没有两个相邻的1的数,例如1, 10, 100, 101. 求第n个Fi-binary number。
题解:数位dp,可以参考画树形图的思考方式。
#include <bits/stdc++.h>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define ll long long
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i)
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Min(a, b) a = min(a, b)
#define Max(a, b) a = max(a, b)
const int maxn = 50;
int T;
int kase;
int n;
ll dp[2][maxn];
void ini(){
dp[0][0] = dp[1][0] = 1;
REP(i, 1, maxn){
dp[1][i] = dp[0][i-1];
dp[0][i] = dp[1][i-1] + dp[0][i-1];
}
}
void solve(){
int ok = 0;
FOR(i, 0, maxn){
if(dp[0][i] < n) putchar('1'), ok = 1, n -= dp[0][i];
else if(ok) putchar('0');
}
}
int main(){
#ifdef ac
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
scanf("%d", &T);
ini();
while(T--){
scanf("%d", &n);
n ++;
printf("Case %d: ", ++ kase);
solve();
puts("");
}
return 0;
}