• 【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;
    }
  • 相关阅读:
    读取XML并绑定至RadioButtonList
    获取客户端IP地址
    Repeater控件数据导出Excel
    验证用户必选CheckBox控件
    限制CheckBoxList控件只能单选
    获取客户端电脑名称
    获取Repeter的Item和ItemIndex
    获取DataList控件的主键和索引
    InsusExportToExcel Library
    ASP.NET网页打印
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444845.html
Copyright © 2020-2023  润新知