zoukankan      html  css  js  c++  java
  • Arranging Your Team

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=35800#problem/D

      1 #include <iostream>
      2 #include <algorithm>
      3 #include <cstring>
      4 #include <string>
      5 #include <cstdio>
      6 #include <vector>
      7 #include <map>
      8 using namespace std;
      9 const int INF=1<<28;
     10 const int N= 32;
     11 
     12 bool vis[N];
     13 vector<int>p[N];
     14 map<string,int>name_id;
     15 map<string,int>pos_id;
     16 int value[N],link[N][N],ans;
     17 
     18 int res()
     19 {
     20     int ans1 = 0;
     21     for (int i = 1; i <= 23; i++)
     22         if(vis[i])
     23             ans1+=value[i];
     24     for (int i = 1; i <= 23; i++)
     25     {
     26         for (int j = i+1; j <= 23; j++)
     27         {
     28             if (vis[i]&&vis[j])
     29                 ans1+= link[i][j];
     30         }
     31     }
     32     return ans1;
     33 }
     34 
     35 void dfs4(int cnt,int pos)
     36 {
     37     if (cnt==4)
     38     {
     39         //cout<<res()<<endl;
     40         ans = max(ans,res());
     41         return ;
     42     }
     43     for (int i = pos; i <(signed)p[4].size(); i++)
     44     {
     45         vis[p[4][i]] = true;
     46         dfs4(cnt+1,i+1);
     47         vis[p[4][i]] = false;
     48     }
     49 }
     50 void dfs3(int cnt,int pos)
     51 {
     52     if (cnt==4)
     53     {
     54         dfs4(0,0);
     55         return ;
     56     }
     57     for (int i = pos; i <(signed)p[3].size(); i++)
     58     {
     59         vis[p[3][i]] = true;
     60         dfs3(cnt+1,i+1);
     61         vis[p[3][i]] = false;
     62     }
     63 }
     64 void dfs2(int cnt,int pos)
     65 {
     66     if (cnt==2)
     67     {
     68         dfs3(0,0);
     69         return ;
     70     }
     71     for (int i = pos; i < (signed)p[2].size(); i++)
     72     {
     73         vis[p[2][i]] = true;
     74         dfs2(cnt+1,i+1);
     75         vis[p[2][i]] = false;
     76     }
     77 }
     78 void dfs1(int cnt,int pos)
     79 {
     80     if (cnt==1)
     81     {
     82         dfs2(0,0);
     83         return;
     84     }
     85     for (int i = pos; i < (signed)p[1].size(); i++)
     86     {
     87         vis[p[1][i]] = true;
     88         dfs1(cnt+1,i+1);
     89         vis[p[1][i]] = false;
     90     }
     91 }
     92 void init()
     93 {
     94     ans = -INF;
     95     name_id.clear();
     96     memset(value,0,sizeof(value));
     97     memset(link,0,sizeof(link));
     98     memset(vis,false,sizeof(vis));
     99     for (int i = 1; i <= 4; i++)
    100         p[i].clear();
    101 }
    102 int main()
    103 {
    104     pos_id["goalkeeper"] = 1;
    105     pos_id["striker"] = 2;
    106     pos_id["midfielder"] = 3;
    107     pos_id["defender"] = 4;
    108     string name,pos;
    109     while(cin>>name)
    110     {
    111         init();
    112         cin>>value[1]>>pos;
    113         name_id[name] = 1;
    114         p[pos_id[pos]].push_back(1);
    115         for (int i = 2; i <= 23; i++)
    116         {
    117             cin>>name>>value[i]>>pos;
    118             name_id[name] = i;
    119             p[pos_id[pos]].push_back(i);
    120         }
    121         int m,val;
    122         string name1,name2;
    123         cin>>m;
    124         while(m--)
    125         {
    126             cin>>name1>>name2>>val;
    127             link[name_id[name1]][name_id[name2]] = val;
    128             link[name_id[name2]][name_id[name1]] = val;
    129         }
    130         if (p[1].size() < 1||p[2].size() < 2||p[3].size() < 4||p[4].size() < 4)
    131         {
    132             printf("impossible
    ");
    133             continue;
    134         }
    135         dfs1(0,0);
    136         printf("%d
    ",ans);
    137     }
    138     return 0;
    139 }
    View Code
  • 相关阅读:
    js动态生成表格
    My97DatePicker显示时间控件的使用方法
    理解Action,Service和Dao功能(转)
    Myeclipseforspring 10破解
    MySQL常用命令(参考资料,部分改动)
    Struts2---Result(传统Web应用程序与Ajax应用程序的异同)
    正则表达式笔记
    day5.字符串内置函数
    day5.数据类型简介
    day4.变量+程序交互
  • 原文地址:https://www.cnblogs.com/lahblogs/p/3410113.html
Copyright © 2011-2022 走看看