WA代码求调
查看原帖
WA代码求调
558833
__Floze3__楼主2023/10/31 20:25
#include <bits/stdc++.h>
using namespace std;

const int maxn = 10005;

long long ans[maxn], n, k;

bool dfs(int u){
    if (u == k) return ans[k] == n;
    bool vis[maxn] = {};
    for (int i = u; i >= 1; i--){
        for (int j = i; j >= 1; j--){
            long long s = ans[i] + ans[j];
            if (vis[s] || s > n || s <= ans[u - 1] || s * (1 << (k - u - 1)) < n) continue;
            ans[u + 1] = s;
            if (dfs(u + 1)) return true;
            else vis[s] = 1;
        }
    }
    return false;
}

int main(){
    ans[1] = 1;
    while(cin >> n, n){
        k = 1;
        while(!dfs(1)) k++;
        for (int i = 1; i <= k; i++) cout << ans[i] << ' ';
        cout << endl;
    }
    return 0;
}
2023/10/31 20:25
加载中...