问题标题: 1630 恢复小木棍

0
1

0
已采纳
颜咏春
颜咏春
中级光能
中级光能

    void dfs(int ans,int sum,int goal,int now){
    if(sum*goal==maxn){printf("%d\n",goal); exit(0);}
    if(maxn-ans<a[cnt])return;  
    if(ans==goal){dfs(0,sum+1,goal,1); return;}
    for( int i=now;i<=cnt;i++)
        if(!use[i] && ans+a[i]<=goal){
            use[i]=1;
            dfs(ans+a[i],sum,goal,i+1);
            use[i]=0;
            if(ans+a[i]==goal || ans==0)break;
            while(a[i]==a[i+1])i++;
        }

0
0
我要回答