栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1812 Stamps

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1812 Stamps

#include<iostream>#include<vector>#include<string.h>#include<stdio.h>#include<algorithm>using namespace std;enum {    SIZ = 108,};int num;int dat[SIZ];int sav[6], st[6];int kind, cnt, last, tie;void output(int p){    if(kind == -1){        printf("%d ---- nonen", p);        return;    }    printf("%d (%d):", p, kind);    if(tie){        printf(" tien");        return ;    }    for(int i=0; i<cnt; i++){        printf(" %d", sav[i]);    }    printf("n");}void dfs(int v, int k, int c, int l, int s){    if(c > 4) return;    if(v == 0){        if(k > kind || (k==kind&&c<cnt)      || (k==kind&&c==cnt && dat[l]>dat[last])){ kind = k, cnt = c, last = l; memcpy(sav, st, sizeof(st)); tie = 0;        } else if(k==kind && c==cnt&&dat[l]==dat[last]){ tie = 1;        }        return;    }    while(s<num){        if(v>=dat[s]) { st[c] = dat[s]; dfs(v-dat[s], k+(l!=s), c+1, s, s);        }        s++;    }}void fun(){    int t;    scanf("%d", &t);    while(t!=0){        kind = -1; tie = 0;        dfs(t, 0, 0, -1, 0);        output(t);        scanf("%d", &t);    }}int readIn(){    num = 0;    if(scanf("%d", &dat[num]) < 0) return 0;    while(dat[num]!=0){        num++;        scanf("%d", &dat[num]);    }    return 1;}int main(){    while(readIn()>0){        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367428.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号