标题:大佬帮我看下这道题 不知道哪错了没法输出 急!!!!!
只看楼主
C好难菜
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-12-16
结帖率:100%
 问题点数:0 回复次数:0 
大佬帮我看下这道题 不知道哪错了没法输出 急!!!!!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int len[64],n,minlen,get;
int b[64];
int cmp(const void *a,const void *b)
{
    return *(int *)a<*(int *)b?1:-1;
}
int dfs(int nowlen,int nowget,int cnt)
{
    if(cnt>=n) return 0;
    if(get==nowget) return 1;
    int i,f=0;
    if(nowlen==0) f=1;
    for(i=cnt;i<n;i++){
        if(len[i]+nowlen==minlen){
            b[i]=1;
            if(dfs(0,nowget+1,nowget)) return 1;
            b[i]=0;
            return 0;
        }
        else if(len[i]+nowlen<minlen){
            b[i]=1;
            if(dfs(nowlen+len[i],nowget,i+1)) return 1;
            b[i]=0;
            if(f) return 0;
            while(i+1<n&&len[i]==len[i+1]) i++;
        }
    }
    return 0;
}
int main()
{
    int i,tollen,q=0,c[100];
    while(scanf("%d",&n),n){
        tollen=0;
        int j=0,p;
        for(i=0;i<n;i++){
            scanf("%d",&p);
            if(p<=50){
                len[j]=p;
                tollen+=len[j];
                j++;
            }
        }
        n=j;
        if(n==0){printf("0\n");
        continue;}
        qsort(len,n,sizeof(int),cmp);
        for(minlen=len[0];;minlen++){
            if(tollen%minlen) continue;
            memset(b,0,sizeof(b));
            get=tollen/minlen;
            if(dfs(0,0,0)){
                c[q]=minlen;
                q++;
                break;
            }
        }
    }
    for(i=0;i<q;i++)
        printf("%d\n",c[i]);
    return 0;
}

搜索更多相关主题的帖子: include int return for i++ 
2018-12-25 17:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-492281-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.814810 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved