设为首页 加入收藏

TOP

HDU 1565 方格取数(1)(状压dp)
2015-07-20 17:29:31 来源: 作者: 【 】 浏览:2
Tags:HDU 1565 方格 状压

感觉这道题目的数据比较水啊,程序的时间复杂度为1711^2*20竟然也可以过掉。。。。其他的就是状压了啊,注意需要滚动一下啊。。。。

方格取数(1)

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5701 Accepted Submission(s): 2159


Problem Description 给你一个n*n的格子的棋盘,每个格子里面有一个非负数。
从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大。
Input 包括多个测试实例,每个测试实例包括一个整数n 和n*n个非负数(n<=20)
Output 对于每个测试实例,输出可能取得的最大的和
Sample Input
3
75 15 21 
75 15 28 
34 70 5 

Sample Output
188

#include 
  
   
#include 
    #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
            
              using namespace std; const int maxn = 22; int dp[2][1<<21]; int mp[maxn][maxn]; int num[1<<22]; int judge(int x) { for(int i = 0; i < 20; i++) if((x&(1<
             
               0) continue; if(j&k) continue; sum = max(sum, dp[0][k]); } dp[1][j] += sum; } for(int j = 0; j < pp && num[j] < (1<
              
               

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 3397 Sequence operation(线.. 下一篇poj 2151 Check the difficulty o..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)