zoukankan      html  css  js  c++  java
  • 【NOIP2007】【Vijos1378】矩阵取数游戏

    problem

    solution

    codes

    //每行独立区间DP, 贪心反例->某行像这样,4 1 1 1 1 1 233 3 3
    //2^80数据, 所以记得高精.
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    using namespace std;
    typedef long long LL;
    typedef __int128 LLL;
    const int maxn = 110;
    int n, m, a[maxn];
    LLL t[maxn], f[maxn][maxn], _max, ans;
    void print(LLL ans){
        if(ans == 0)return ;
        else print(ans/10);
        putchar(ans%10+'0');
    }
    int main(){
        cin>>n>>m;
        t[0] = 1;
        for(int i = 1; i <= m; i++)t[i] = t[i-1]*2;
        while(n--){
            for(int i = 1; i <= m; i++)cin>>a[i];
            memset(f, 0, sizeof f);
            //for(int i = 1; i <= m; i++)f[i][i] = t[m]*a[i];//边界条件
            //f[i][j]:这行还剩下[i,j]时能得到的最高分
            //转移加上分别取了左边的和右边的数的时候的得分
            for(int i = 1; i <= m; i++)
                for(int j = m; j >= i; j--)
                    f[i][j]=max(f[i-1][j]+t[m-(j-i+1)]*a[i-1], f[i][j+1]+t[m-(j-i+1)]*a[j+1]);
            //枚举最后一个取的是哪个数,得到这一行的最高分
            _max = 0;
            for(int i = 1; i <= m; i++)_max = max(_max, f[i][i]+t[m]*a[i]);
            ans += _max;
        }
        if(ans == 0)cout<<"0
    ";
        else print(ans);
        return 0;
    }
  • 相关阅读:
    Nginx安装
    node.js搭建vue脚手架
    Oracle引入数据
    MVC引入Junit单元测试
    Git版本控制器
    IDEA-Maven
    SSM框架整合
    【测试基础第五篇】测试用例编写和评审
    【测试基础第四篇】测试用例设计方法
    【测试基础第三篇】需求测试分析
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444845.html
Copyright © 2011-2022 走看看