UVALive 5025 (dfs)
来源:互联网 发布:滨州行知中学的邮编 编辑:程序博客网 时间:2024/04/29 13:31
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3026
题意:给你23个人的球员信心,还有组合效果,问如何取球员使得最后的效果最好;
思路:直接深搜可以过,这里需要注意可能为负值,还有限定的需要4个d,4个m,2个s,1个g。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <map>using namespace std;int val[30],cnt,sumd,summ,sums,sumg,m;int addv[30][30],ans,flag[30];int s[5];bool used[30];struct node{ int u,v; int aval;} add[450];inline int id(char a[]){ if(a[0]=='d') { sumd++; return 0; } else if(a[0]=='m') { summ++; return 1; } else if(a[0]=='s') { sums++; return 2; } else { sumg++; return 3; }}void dfs(int res,int x){ if(!s[0]&&!s[1]&&!s[2]&&!s[3]) { for(int i=0; i<m; i++) if(used[add[i].u]&&used[add[i].v]) res+=add[i].aval; ans=max(ans,res); return ; } for(int i=x; i<23; i++) if(!used[i]&&s[flag[i]]) { used[i]=1; s[flag[i]]--; dfs(res+val[i],i+1); used[i]=0; s[flag[i]]++; }}int main(){ char name[35],pos[35]; int tval; while(~scanf("%s%d%s",name,&tval,pos)) { cnt=sumd=summ=sums=sumg=0; map<string,int>my; my[name]=cnt++; flag[cnt-1]=id(pos); val[cnt-1]=tval; for(int i=0; i<22; i++) { scanf("%s%d%s",name,&tval,pos); my[name]=cnt++; flag[cnt-1]=id(pos); val[cnt-1]=tval; } scanf("%d",&m); for(int i=0; i<m; i++) { scanf("%s%s%d",name,pos,&tval); int u=my[name],v=my[pos]; add[i].u=u,add[i].v=v,add[i].aval=tval; } if(sumd<4||summ<4||sums<2||sumg<1) { puts("impossible"); continue; } memset(used,0,sizeof(used)); s[0]=4,s[1]=4,s[2]=2,s[3]=1; ans=-1000000000; dfs(0,0); printf("%d\n",ans); } return 0;}
- UVALive 5025 (dfs)
- UVALive 5025 Arranging Your Team dfs
- [dfs] UVALive 3667 Ruler
- uvalive 3667(dfs)
- UVALive 7606Percolation(DFS)
- UVALive 3667 dfs
- UVAlive-7426 Debugging(dfs)
- 【割点 && dfs】UVALive
- uvalive 6902 Three Squares - dfs
- UVALive 6432 Influence // 暴力dfs
- UVAlive 3092 无根树->有根树 dfs
- UVALive 7043 字典树+DFS
- UVALive 4743 (Alice's Cube)DFS
- UVALive 5116 Dividing Stones(dfs + 打表)
- UVALive 6527 Counting ones dfs(水
- UVALive 6450 Social Advertising DFS解法
- Uvalive 6259 Word equations dfs+dp
- UVALive 6850 Hidden Plus Signs(dfs)
- 自定义通信协议
- MapKit基本知识
- 分享一个简单的Android日志文件记录类
- 项目过程之间的关系分析
- 三角函数公式
- UVALive 5025 (dfs)
- 在ARM+LINUX上使用pppd拔号上网(GPRS)流程
- IOS MapKit学习笔记
- ubuntu12.10 电源管理
- 看我是如何快速学习android开发的
- Never store the password unhased directly on the server!
- 向SDE图层中添加大量数据时,出现ORA-00604以及ORA-01000的解决办法
- 上传文件
- iphone开发-地图注解(地图上的大头针)