求助,为什么CSP报零,洛谷AC?
查看原帖
求助,为什么CSP报零,洛谷AC?
218511
pevernow楼主2020/11/16 21:55

几乎完全一样的代码

#include<iostream>
using namespace std;
int list[]={
    2,
    4,
    8,
    16,
    32,
    64,
    128,
    256,
    512,
    1024,
    2048,
    4096,
    8192,
    16384,
    32768,
    65536,
    131072,
    262144,
    524288,
    1048576,
    2097152,
    4194304,
    8388608
};
bool tryy(int n,int i=0){
    if(n==0){
        return true;
    }else{
    	if(n<0) return false;
	}
    for(;i<23;i++){
        if(tryy(n-list[i],i+1)==true){
            cout<<list[i]<<' ';
            return true;
        }
    }
    return false;
}
int main(){
    int a;
    cin>>a;
    if(tryy(a)==false){
    	cout<<"-1";
	}
}
2020/11/16 21:55
加载中...