• 【BZOJ 3997】 3997: [TJOI2015]组合数学 (DP| 最小链覆盖=最大点独立集)


     

    3997: [TJOI2015]组合数学

    Time Limit: 20 Sec  Memory Limit: 128 MB
    Submit: 919  Solved: 664

    Description

     给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右走。问至少走多少次才能将财宝捡完。此对此问题变形,假设每个格子中有好多财宝,而每一次经过一个格子至多只能捡走一块财宝,至少走多少次才能把财宝全部捡完。

    Input

     第一行为正整数T,代表数据组数。

    每组数据第一行为正整数N,M代表网格图有N行M列,接下来N行每行M个非负整数,表示此格子中财宝数量,0代表没有

    Output

     输出一个整数,表示至少要走多少次。

    Sample Input

    1
    3 3
    0 1 5
    5 0 0
    1 0 0

    Sample Output

    10

    HINT

     N<=1000,M<=1000.每个格子中财宝数不超过10^6

    Source

    【分析】

      很神呢,我都想不到。

      Po姐:Dilworth定理:DAG的最小链覆盖=最大点独立集 

      独立点就是左下到右上的咯。

      你也可以看这位大神

      

      然后就是一个DP。。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<algorithm>
     6 using namespace std;
     7 #define Maxn 1010
     8 
     9 int mymin(int x,int y) {return x<y?x:y;}
    10 int mymax(int x,int y) {return x>y?x:y;}
    11 
    12 int a[Maxn][Maxn],f[Maxn][Maxn];
    13 
    14 int main()
    15 {
    16     int T;
    17     scanf("%d",&T);
    18     while(T--)
    19     {
    20         int n,m;
    21         scanf("%d%d",&n,&m);
    22         for(int i=1;i<=n;i++)
    23          for(int j=1;j<=m;j++)
    24           scanf("%d",&a[i][j]);
    25         memset(f,0,sizeof(f));
    26         for(int i=n;i>=1;i--)
    27          for(int j=1;j<=m;j++)
    28          {
    29              f[i][j]=mymax(mymax(f[i+1][j],f[i][j-1]),f[i+1][j-1]+a[i][j]);
    30          }
    31         printf("%d
    ",f[1][m]);
    32     }
    33     return 0;
    34 }
    View Code

    2017-04-08 10:04:37

      

  • 相关阅读:
    A Famous City
    A Famous ICPC Team
    配置单元测试环境,找不到SenTestingKit
    linux解压.tar命令
    语音输入——科大讯飞
    查看dsym错误信息
    工程里关闭arc
    导入签名错误
    mac显示隐藏文件
    类uialertview弹出动画
  • 原文地址:https://www.cnblogs.com/Konjakmoyu/p/6680997.html
Copyright © 2020-2023  润新知