bzoj3997 组合数学

  组合数学

题目背景:

bzoj3997

分析:首先注意,我们可以把原题抽象成为一张DAG,然后每个格子可以走到相邻的下方或者右方的格子,但是当前格子中的每一个点互不联通,然后,我们就可以发现原题就是求取一个DAG的最小链覆盖,然后根据

Dilworth定理(我也不知道这是什么,太蒟蒻······):

DAG的最小链覆盖 = 最大独立点集

然后根据每个格子与右下连边,并且,每个格子中的点互不联通可得,本题就是一个求取从右上到左下的和最大的链的过程,并且,我们需要满足对于任意按顺序的链上的两点,Xi+1 > Xi, Yi+1< Yi(严格满足)

Source

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             using namespace std; inline char read() { static const int IN_LEN = 1024 * 1024; static char buf[IN_LEN], *s, *t; if (s == t) { t = (s = buf) + fread(buf, 1, IN_LEN, stdin); if (s == t) return -1; } return *s++; } template 
            
              inline bool R(T &x) { static bool iosig; static char c; for (c = read(), iosig = false; !isdigit(c); c = read()) { if (c == -1) return false; if (c == '-') iosig = true; } for (x = 0; isdigit(c); c = read()) x = (x << 3) + (x << 1) + (c ^ '0'); if (iosig) x = -x; return true; } const int OUT_LEN = 1024 * 1024; char obuf[OUT_LEN], *oh = obuf; inline void writechar(char c) { if (oh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf; *oh++ = c; } template 
             
               inline void W(T x) { static int buf[30], cnt; if (!x) writechar(48); else { if (x < 0) writechar('-'), x = -x; for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48; while (cnt) writechar(buf[cnt--]); } } inline void flush() { fwrite(obuf, 1, oh - obuf, stdout); } const int MAXN = 1000 + 10; const int MAXM = 1000 + 10; int n, m, t; int map[MAXN][MAXM], dp[MAXN][MAXM]; inline void readin() { R(n), R(m); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) R(map[i][j]); } /*求取最长的链,从右上到左下角,注意这里的链上的数据, 要严格满足Xi < Xi+1, Yi > Yi+1*/ inline void work() { for (int i = 1; i <= n; ++i) for (int j = m; j >= 1; --j) dp[i][j] = max(dp[i - 1][j + 1] + map[i][j], max(dp[i - 1][j], dp[i][j + 1])); W(dp[n][1]), writechar('\n'); } /*所以就是一个5行的dp就好了······*/ int main() { R(t); while (t--) { readin(); work(); } flush(); return 0; } 
              
             
            
           
          
         
       
      
      
     
     
    
    
   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值