HDU2167(SummerTrainingDay02-D 状态压缩dp)
Pebbles
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1820 Accepted Submission(s): 1034
Problem Description

The player distributes pebbles across the board so that:
?At most one pebble resides in any given square.
?No two pebbles are placed on adjacent squares. Two squares are considered adjacent if they are horizontal, vertical, or even diagonal neighbors. There's no board wrap, so 44 and 61 of row three aren't neighbors. Neither are 33 and 75 nor 55 and 92.
The goal is to maximize the number of points claimed by your placement of pebbles.
Write a program that reads in a sequence of boards from an input file and prints to stdout the maximum number of points attainable by an optimal pebble placement for each.
Input
Output
Sample Input
85 50 74 94 28
92 96 23 71 10
23 61 31 30 46
64 33 32 95 89
78 78 11 55 20 11
98 54 81 43 39 97
12 15 79 99 58 10
13 79 83 65 34 17
85 59 61 12 58 97
40 63 97 85 66 90
33 49 78 79 30 16 34 88 54 39 26
80 21 32 71 89 63 39 52 90 14 89
49 66 33 19 45 61 31 29 84 98 58
36 53 35 33 88 90 19 23 76 23 76
77 27 25 42 70 36 35 91 17 79 43
33 85 33 59 47 46 63 75 98 96 55
75 88 10 57 85 71 34 10 59 84 45
29 34 43 46 75 28 47 63 48 16 19
62 57 91 85 89 70 80 30 19 38 14
61 35 36 20 38 18 89 64 63 88 83
45 46 89 53 83 59 48 45 87 98 21
15 95 24 35 79 35 55 66 91 95 86 87
94 15 84 42 88 83 64 50 22 99 13 32
85 12 43 39 41 23 35 97 54 98 18 85
84 61 77 96 49 38 75 95 16 71 22 14
18 72 97 94 43 18 59 78 33 80 68 59
26 94 78 87 78 92 59 83 26 88 91 91
34 84 53 98 83 49 60 11 55 17 51 75
29 80 14 79 15 18 94 39 69 24 93 41
66 64 88 82 21 56 16 41 57 74 51 79
49 15 59 21 37 27 78 41 38 82 19 62
54 91 47 29 38 67 52 92 81 99 11 27
31 62 32 97 42 93 43 79 88 44 54 48
Sample Output
683
2096
2755
Source
//2017-08-02
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int arr[][];
int dp[][], sum[][];//dp[i][j]表示第i行使用第j种方法所能得到的最大值,sum[i][j]表示第i行使用第j种方法所得的和
int state[];//表示可行的状态,即可行的取数方法
int len, n; bool ok(int sta)//可行状态,即1的位置两两不相邻
{
return (sta&(sta<<))== ? true : false;
} int get_sum(int pos, int x)//求第pos行,使用x方法能取得的和
{
int sum = , cnt = ;
while(x)
{
sum += (x%)*arr[pos][n-cnt];
x >>= ;
cnt++;
}
return sum;
} void init(int m)//初始化
{
len = ;
for(int i = ; i < (<<m); i++)
if(ok(i))state[len++] = i;
for(int i = ; i < n; i++)
for(int j = ; j < len; j++)
sum[i][j] = get_sum(i, state[j]);
memset(dp, , sizeof(dp));
for(int i = ; i < len; i++)
dp[][i] = sum[][i];
} void read(){
char str[];
int row = ;
while(cin.getline(str, )){
if(strlen(str) == )break;
for(int i = ; i < strlen(str); i+=){
arr[row][i/] = (str[i]-'')*+(str[i+]-'');
}
row++;
}
n = row;
} int main()
{
while()
{
read();
if(n == )break;
init(n);
for(int i = ; i < n; i++)//处理第i行
for(int j = ; j < len; j++)//采取第j种方法
for(int k = ; k < len; k++)//枚举上一行所采取的方法k
if((state[j]&state[k])== && ((state[j]<<)&state[k])== && ((state[j]>>)&state[k])==)//方法j、k可行。
dp[i][j] = max(dp[i][j], dp[i-][k]+sum[i][j]);//状态转移方程 int ans = ;
for(int i = ; i < len; i++)//找出最大值
if(dp[n-][i]>ans)
ans = dp[n-][i]; cout<<ans<<endl;
}
return ;
}
HDU2167(SummerTrainingDay02-D 状态压缩dp)的更多相关文章
- 状态压缩dp(hdu2167,poj2411)
hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...
- HDU2167+状态压缩DP
状态压缩dp 详见代码 /* 状态压缩dp dp[ i ][ j ]:第i行j状态的最大和 dp[i][j] = max( dp[i-1][k]+sum[i][j] ); 题意:给定一个N*N的方格, ...
- HDU1565+状态压缩dp
简单的压缩状态 dp /* 状态压缩dp 同hdu2167 利用滚动数组!! */ #include<stdio.h> #include<string.h> #include& ...
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
随机推荐
- MariaDB 连接查询与子查询(6)
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...
- 23_pikle/shevel/json
一.序列化 存储数据或者传输数据时,需要把对象进行处理,把对象处理成方便存储和传输的数据格式.不同的序列化,结果也不同. 序列化方式: (1) pickle 可以将 ...
- 人工智能-机器学习之Selenium(chrome驱动,火狐驱动)
selenium是一个用于web应用程序测试的工具,Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Firefox.Mozilla Suite等 ...
- 03-02 Java键盘录入
键盘录入基本格式: /* 为了让程序的数据更符合开发的数据,我们就加入了键盘录入. 让程序更灵活一下. 那么,我们如何实现键盘数据的录入呢? A:导包 格式: import java.util.Sca ...
- 课程一(Neural Networks and Deep Learning),第二周(Basics of Neural Network programming)—— 3、Python Basics with numpy (optional)
Python Basics with numpy (optional)Welcome to your first (Optional) programming exercise of the deep ...
- webgl之五彩光源
一.Three.js中有哪些光源? 在Three.js中,光源有一个基类THREE.Light(hex),这个hex接受16进制颜色作为参数而初始化光源的颜色,比如我们要定义一种绿色的光源,可以这样来 ...
- keepalived双机热备,安装部署文档
keepalived双击热备,安装部署文档: 下载目录:/apps/keepalived-1.2.7.tar.gz 1:---> yum install -y make wget 2:---&g ...
- 如何让你的网站用上免费的HTTPS
因为之前网站上被注入了广告,再百般尝试之后最后还是使用了HTTPS解决了. 在实现HTTPS的时候最关键的就是证书. 证书的质量觉得了你被多少浏览器所信任. 证书的价格也就蹭蹭蹭往上涨了. 这里推荐一 ...
- 配置codis-dashboard
codis-dashboard主要用来codis配置使用,也就是说所有的相关的配置项必须通过此进程完成,本演习在60服务上配置测试. 利用codis本身提供的命令自动生成配置文件:1.生成dashbo ...
- Tensorflow运用RNN注意事项
一.学习单步的RNN:RNNCell 如果要学习TensorFlow中的RNN,第一站应该就是去了解“RNNCell”,它是TensorFlow中实现RNN的基本单元,每个RNNCell都有一个cal ...