HDU 2167 Pebbles 状态压缩dp
Pebbles
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 795 Accepted Submission(s): 439

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.
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
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; int a[][];
int state[],len;//
int Num[][];
int befor[];
int now[];
void Init()
{
int i,k=<<;
len=;
for(i=;i<k;i++)
{
if( (i&(i>>)) || (i&(i<<)) );
else
state[len++]=i;
}
}
void make_init(int n)
{
int i,j,k=<<n,ans,x;
memset(Num,,sizeof(Num));
for(i=;i<=n;i++)
{
for(j=;j<len&&state[j]<k;j++)
{
x=state[j];
ans=;
while(x)
{
if(x&)
{
Num[i][j]+=a[i][ans];
}
x=x>>;
ans++;
}
}
}
}
void solve(int n)
{
int i,j,k=<<n,s,hxl;
memset(befor,,sizeof(befor));
memset(now,,sizeof(now));
for(i=;i<=n;i++)
{
for(j=;j<len&&state[j]<k;j++)
{
hxl=;
for(s=;s<len&&state[s]<k;s++)
{
if( (state[j]&state[s]) )continue;
if( ((state[j]<<)&state[s]) || ((state[j]>>)&state[s]) ) continue;
if(hxl<befor[s])
hxl=befor[s];
}
now[j]=hxl+Num[i][j];
}
for(j=;j<len&&state[j]<k;j++)
{
befor[j]=now[j];
now[j]=;
}
}
for(i=,hxl=;i<len&&state[i]<k;i++)
if(hxl<befor[i])
hxl=befor[i];
printf("%d\n",hxl);
}
int main()
{
int n;
int i,j,tom,k;
char c[];
Init();
while(gets(c+)>)
{
k=strlen(c+);
if(k==)continue;
for(tom=,i=,n=;i<=k;i++)
{
if(c[i]>=''&&c[i]<='')
{
tom=tom*+c[i]-'';
}
else
{
a[][++n]=tom;
tom=;
}
}
a[][++n]=tom; for(i=;i<=n;i++)
for(j=;j<=n;j++)
scanf("%d",&a[i][j]); make_init(n);
solve(n);
}
return ;
}
HDU 2167 Pebbles 状态压缩dp的更多相关文章
- HDOJ 2167 Pebbles (状态压缩dp)
题意:给你一个n*n的矩阵,让你从矩阵中选择一些数是的他们的和最大,规则是:相邻的两个数不能同时取,位置为(i,j)的数与(i+1,j),(i-1,j),(i,j+1),(i,j-1),(i+1,j+ ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- HDU 3001(状态压缩dp)
状态压缩dp的第一题! 题意:Mr ACMer想要进行一次旅行,他决定访问n座城市.Mr ACMer 可以从任意城市出发,必须访问所有的城市至少一次,并且任何一个城市访问的次数不能超过2次.n座城市间 ...
- hdu 4856 Tunnels 状态压缩dp
Tunnels Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- HDU 3001【状态压缩DP】
题意: 给n个点m条无向边. 要求每个点最多走两次,要访问所有的点给出要求路线中边的权值总和最小. 思路: 三进制状态压缩DP,0代表走了0次,1,2类推. 第一次弄三进制状态压缩DP,感觉重点是对数 ...
- HDU 2167 Pebbles(状压DP)
题目链接:Pebbles Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- hdu 5045 Contest(状态压缩DP)
题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...
- hdu 3091 Necklace 状态压缩dp *******
Necklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others)Total ...
- hdu 4628 Pieces 状态压缩dp
Pieces Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
随机推荐
- svn提交新文件夹同时不需要更新全部上级目录
关于svn的指定目录指定位置更新:当在提交了新建的目录后可以使用 a) 在需要更新的上级目录上单击右键 在延伸菜单中选择 b) 弹出对话框中选择,check repository c) 新添加的 ...
- 【转】MVC,MVP 和 MVVM 的图示
复杂的软件必须有清晰合理的架构,否则无法开发和维护. MVC(Model-View-Controller)是最常见的软件架构之一,业界有着广泛应用.它本身很容易理解,但是要讲清楚,它与衍生的 MVP ...
- Linux 包管理器
RPM: rpm(Red-Hat Package Manager) 为 Redhat 提出的包管理器, 用于在 Redhat 及其衍生版本中安装 rpm 格式的软件包 rpm 的优点: 1.简化了源码 ...
- HTML5本地存储——IndexedDB二:索引
HTML5本地存储——IndexedDB(二:索引) 在HTML5本地存储——IndexedDB(一:基本使用)中介绍了关于IndexedDB的基本使用方法,很不过瘾,这篇我们来看看indexed ...
- 程序设计中的dry原则
DRY:dont repeat yourself 假设一个逻辑(代码块)会重复两次或者以上,应该写成函数被调用 为什么呢,实际上,我们处处可见重复性的代码.这除了增加工作量之外,还会增加维护难度. d ...
- TensorFlow GPU 的使用
一.TensorFlow 设备分配 1.设备分配规则 If a TensorFlow operation has both CPU and GPU implementations, the GPU d ...
- C#之集合
数组(http://www.cnblogs.com/afei-24/p/6738128.html)的大小是固定的.如果元素的个数是动态的,就应使用集合类. 列表(http://www.cnblogs. ...
- SPOJ - COT 路径构造主席树
题意:给出一个带权树,多次询问路径\((u,v)\)的第k小权值 这是主席树往区间扩展到树上的套路题 由于是按路径查询,我们无法使用dfs序,但可利用主席树对父亲扩展的方法构造出链 因此要用dfs构造 ...
- 剑指offer——链表
#include"stdio.h" #include"stdlib.h" #include"iostream" using namespac ...
- 向指定url发送请求与获取响应
string url = @"https://www.baidu.com"; //向指定服务器发起请求 HttpWebRequest request = (HttpWebReque ...