• HDU 3720 Arranging Your Team(DFS)


    题目链接

    队内赛里,匆匆忙忙写的。

      1 #include <cstdio>
      2 #include <cstring>
      3 #include <iostream>
      4 #include <vector>
      5 #include <string>
      6 #include <map>
      7 #include <algorithm>
      8 using namespace std;
      9 int v[30];
     10 int flag[30];
     11 int o[30][30];
     12 int p[30];
     13 char name[51];
     14 char fa[51];
     15 int que[6][30];
     16 int s[6];
     17 int sf[30];
     18 int key[6];
     19 int maxz;
     20 int judge(char *str)
     21 {
     22     if(strcmp("goalkeeper",str) == 0)
     23         return 1;
     24     else if(strcmp("defender",str) == 0)
     25         return 2;
     26     else if(strcmp("midfielder",str) == 0)
     27         return 3;
     28     else if(strcmp("striker",str) == 0)
     29         return 4;
     30     return 0;
     31 }
     32 void dfs(int y,int x,int step,int sd)
     33 {
     34     int i,j,k,st;
     35     if(step > 4)
     36     {
     37         st = 0;
     38         for(j = 0;j < 11;j ++)
     39         st += v[p[j]];
     40         for(j = 0; j < 11; j ++)
     41         {
     42             for(k = j+1; k < 11; k ++)
     43                 st += o[p[j]][p[k]];
     44         }
     45         maxz = max(st,maxz);
     46         return ;
     47     }
     48     for(i = y;i < s[step];i ++)
     49     {
     50         if(!sf[que[step][i]])
     51         {
     52             sf[que[step][i]] = 1;
     53             p[sd] = que[step][i];
     54             if(x+1 > key[step])
     55             dfs(0,1,step+1,sd+1);
     56             else
     57             dfs(i+1,x+1,step,sd+1);
     58             sf[que[step][i]] = 0;
     59         }
     60     }
     61     return ;
     62 }
     63 int main()
     64 {
     65     int i,m,sc;
     66     key[1] = 1;
     67     key[2] = 4;
     68     key[3] = 4;
     69     key[4] = 2;
     70     while(scanf("%s%d%s",name,&v[0],fa)!=EOF)
     71     {
     72         memset(o,0,sizeof(o));
     73         memset(s,0,sizeof(s));
     74         memset(sf,0,sizeof(sf));
     75         memset(que,0,sizeof(que));
     76         map<string,int> mp;
     77         mp[name] = 0;
     78         flag[0] = judge(fa);
     79         que[flag[0]][s[flag[0]]] = 0;
     80         s[flag[0]] ++;
     81         for(i = 1; i < 23; i ++)
     82         {
     83             scanf("%s%d%s",name,&v[i],fa);
     84             mp[name] = i;
     85             flag[i] = judge(fa);
     86             que[flag[i]][s[flag[i]]] = i;
     87             s[flag[i]] ++;
     88         }
     89         scanf("%d",&m);
     90         for(i = 0; i < m; i ++)
     91         {
     92             scanf("%s%s%d",name,fa,&sc);
     93             int a,b;
     94             a = mp[name];
     95             b = mp[fa];
     96             o[a][b] += sc;
     97             o[b][a] += sc;
     98         }
     99         if(s[1] < 1||s[2] < 4||s[3] < 4||s[4] < 2)
    100         {
    101             printf("impossible
    ");
    102             continue;
    103         }
    104         maxz = -100000000;
    105         dfs(0,1,1,0);
    106         printf("%d
    ",maxz);
    107     }
    108     return 0;
    109 }
  • 相关阅读:
    flask基础之jijia2模板使用基础(二)
    python之微信公众号开发(基本配置和校验)
    flask插件系列之SQLAlchemy基础使用
    python基础之常用的高阶函数
    服务器部署之nginx的配置
    python之gunicorn的配置
    python内置模块之unittest测试(五)
    python之celery使用详解一
    git服务器的简单搭建
    python模块分析之logging日志(四)
  • 原文地址:https://www.cnblogs.com/naix-x/p/3405216.html
Copyright © 2020-2023  润新知