ZOJ 2192 T-Shirt Gumbo(DFS)
来源:互联网 发布:怎么进入淘宝店铺 编辑:程序博客网 时间:2024/06/05 04:27
普通的搜索会超时
可以剪的地方:
1.库存里没有T-shirt了可以剪掉
2.刚开始对各个参赛者的大小要求范围按最小的排个序,再进行搜索
#include <iostream>#include <cstdio>#include <memory.h>#include <algorithm>#include <string>using namespace std;const int maxn=50;char buf[maxn],tb[90];string dem[30];int iv[10],n;void init(){tb['S']=0;tb['M']=1;tb['L']=2;tb['X']=3;tb['T']=4;}bool cmp(const string &str1 ,const string &str2){return tb[str1[0]]<tb[str2[0]];}bool dfs(int curi){if(curi==n){return true;}for (int i=tb[dem[curi][0]];i<=tb[dem[curi][1]];++i){if(iv[i]>0){iv[i]--;for (int j=0;j<5;++j){if(iv[j]>0||curi+1==n){//必须有库存才继续,否则剪掉if(dfs(curi+1))return true;break;}}iv[i]++;}}return false;}int main(){init();while (scanf("%s",buf)&&strcmp(buf,"ENDOFINPUT")){scanf("%d",&n);for (int i=0;i<n;++i){scanf("%s",buf);dem[i]=buf;}sort(dem,dem+n,cmp);//对范围按最小的排个序for (int i=0;i<5;++i){scanf("%d",&iv[i]);}if(dfs(0)){printf("T-shirts rock!\n");}else{printf("I'd rather not wear a shirt anyway...\n");}scanf("%s",buf);}return 0;}
- ZOJ 2192 T-Shirt Gumbo(DFS)
- zoj 2192 || poj 2584 T-Shirt Gumbo
- 2584 T-Shirt Gumbo // MaxMatch
- POJ-2584-T-Shirt Gumbo
- poj 2584T-Shirt Gumbo
- poj 2584 T-Shirt Gumbo
- POJ 2584 T-Shirt Gumbo
- POJ2584 T-Shirt Gumbo 最大流
- T-Shirt Gumbo 二分最大匹配 hoj
- poj 2584 T-Shirt Gumbo(最大流)
- 【POJ】2584 T-Shirt Gumbo 最大流
- poj2584——T-Shirt Gumbo
- poj 2584 T-Shirt Gumbo(最大匹配 )
- poj 2584 T-Shirt Gumbo 二分匹配
- poj 2584 T-Shirt Gumbo 最大匹配
- poj 2584 T-Shirt Gumbo 最大匹配
- Poj 2584 T-Shirt Gumbo【最大流】
- POJ 2584 T-Shirt Gumbo 最大流和多重匹配
- iphone UI元素集
- 批量删除sql
- UIBarButtonSystemItem样式
- OpenCV 学习笔记---基本数据类型
- ajax实例1
- ZOJ 2192 T-Shirt Gumbo(DFS)
- XML文件的操作
- Mac 显示隐藏文件
- Linux学习笔记: 操作文件及目录的13个命令
- 语音识别:现状
- iOS strong 和weak的形象理解
- JUnit4的测试类
- Unexpected Result from Calling a Non-static Function with class::method()
- 微软面试题<二>