zoukankan      html  css  js  c++  java
  • hdu 6435 CSGO

    题意:现在有n个主武器, m个副武器, 你要选择1个主武器,1个副武器, 使得 题目给定的那个式子最大。

    题解:这个题目困难的地方就在于有绝对值,| a - b | 我们将绝对值去掉之后 他的值就为 max{ a-b, b-a }.

    由于题目中状态最多也是5维, 所以我们对与这五维枚举他的状态, 是被减还是是加。然后状压标记对应的状态。

    最后遍历所有状态, 然后找到最大值就好了。

    代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define Fopen freopen("std.in","r",stdin); freopen("_out.txt","w",stdout);
     4 #define LL long long
     5 #define ULL unsigned LL
     6 #define fi first
     7 #define se second
     8 #define pb push_back
     9 #define lson l,m,rt<<1
    10 #define rson m+1,r,rt<<1|1
    11 #define lch tr[x].son[0]
    12 #define rch tr[x].son[1]
    13 #define max3(a,b,c) max(a,max(b,c))
    14 #define min3(a,b,c) min(a,min(b,c))
    15 typedef pair<int,int> pll;
    16 const int inf = 0x3f3f3f3f;
    17 const LL INF = 0x3f3f3f3f3f3f3f3f;
    18 const LL mod =  (int)1e9+7;
    19 const int N = 1024;
    20 LL A[N], B[N], t[N];
    21 int main(){
    22     int T, n, m, k, val;
    23     scanf("%d", &T);
    24     while(T--){
    25         scanf("%d%d%d", &n, &m, &k);
    26         LL sum;
    27         memset(A, -INF, sizeof(A));
    28         memset(B, -INF, sizeof(B));
    29         while(n--){
    30             scanf("%d", &val);
    31             for(int i = 0; i < k; i++)
    32                 scanf("%lld", &t[i]);
    33             for(int i = 0; i < (1<<k); i++){
    34                 sum = val;
    35                 for(int j = 0; j < k; j++){
    36                     if((i>>j)&1) sum+=t[j];
    37                     else sum -= t[j];
    38                 }
    39                 A[i] = max(A[i], sum);
    40             }
    41         }
    42         LL ans = 0;
    43         while(m--){
    44             scanf("%d", &val);
    45             for(int i = 0; i < k; i++)
    46                 scanf("%lld", &t[i]);
    47             for(int i = 0; i < (1<<k); i++){
    48                 sum = val;
    49                 for(int j = 0; j < k; j++){
    50                     if((i>>j)&1) sum+=t[j];
    51                     else sum -= t[j];
    52                 }
    53                 B[i] = max(B[i], sum);
    54                 ans = max(ans, B[i] + A[(1<<k)-1-i]);
    55             }
    56         }
    57         printf("%lld
    ", ans);
    58     }
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    easypoi添加下拉预选值
    java启动项目字符编码和配置文件的字符编码问题
    leetcode
    leetcode
    leetcode
    leetcode
    事务的隔离级别- 极客时间()
    数据库的事务
    SQL中的视图(极客时间)
    SQL中的连接(极客时间)
  • 原文地址:https://www.cnblogs.com/MingSD/p/9523099.html
Copyright © 2011-2022 走看看