1453D - Checkpoints
D - Checkpoints
兩個1之間肯定是獨立的,卡在不會算期望(
數學真的殺我
為啥不試試遞推呢,自信到覺得能嗯算
設 P n P_n Pn為n個0的期望
p n = 1 2 ( P n − 1 + 1 ) + 1 2 ( P n − 1 + 1 + P n ) p_n = \frac{1}{2}(P_{n -1} + 1) + \frac{1}{2}(P_{n -1}+ 1+P_n) pn=21(Pn−1+1)+21(Pn−1+1+Pn)
化簡: P n = P n − 1 × 2 + 2 P_n = P_{n-1} \times 2 +2 Pn=Pn−1×2+2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p[100];
inline void init() {
p[0] = 2;
for(int i = 1; i <= 60; ++i) {
p[i] = p[i - 1] * 2 + 2;
}
}
int main() {
init();
//cout << p[60] << endl;
int T;
cin >> T;
while(T--) {
ll k;
cin >> k;
if(k & 1) {
cout << -1 << endl;
continue;
}
vector<int> ans;
ans.clear();
for(int i = 60; i >= 0; --i) {
if(k >= p[i]) {
while(k >= p[i]) {
ans.push_back(i);
k -= p[i];
}
}
}
int sum = 0;
for(auto x : ans) {
sum += x + 1;
}
cout << sum << endl;
for(auto x : ans) {
cout << 1 << " ";
for(int i = 0; i < x; ++i) {
cout << 0 << " ";
}
}
cout << endl;
}
}