Pebbles

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 795    Accepted Submission(s): 439

Problem Description
You're given an unlimited number of pebbles to distribute across an N x N game board (N drawn from [3, 15]), where each square on the board contains some positive point value between 10 and 99, inclusive. A 6 x 6 board might look like this:

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
Each board is expressed as a series of lines, where each line is a space-delimited series of numbers. A blank line marks the end of each board (including the last one)

 
Output
then your program would print the maximum number of points one can get by optimally distributing pebbles while respecting the two rules, which would be this (each output should be printed on a single line and followed with a newline):

 
Sample Input
71 24 95 56 54
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
572
683
2096
2755
 
Source
 
题目:要求选择了一个点后,其周围8个点都不能取。
        总是弄错,然后写了3遍,发现一开始写的是对的。......
 
 #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的更多相关文章

  1. HDOJ 2167 Pebbles (状态压缩dp)

    题意:给你一个n*n的矩阵,让你从矩阵中选择一些数是的他们的和最大,规则是:相邻的两个数不能同时取,位置为(i,j)的数与(i+1,j),(i-1,j),(i,j+1),(i,j-1),(i+1,j+ ...

  2. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  3. HDU 3001(状态压缩dp)

    状态压缩dp的第一题! 题意:Mr ACMer想要进行一次旅行,他决定访问n座城市.Mr ACMer 可以从任意城市出发,必须访问所有的城市至少一次,并且任何一个城市访问的次数不能超过2次.n座城市间 ...

  4. hdu 4856 Tunnels 状态压缩dp

    Tunnels Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem ...

  5. HDU 3001【状态压缩DP】

    题意: 给n个点m条无向边. 要求每个点最多走两次,要访问所有的点给出要求路线中边的权值总和最小. 思路: 三进制状态压缩DP,0代表走了0次,1,2类推. 第一次弄三进制状态压缩DP,感觉重点是对数 ...

  6. HDU 2167 Pebbles(状压DP)

    题目链接:Pebbles Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. hdu 5045 Contest(状态压缩DP)

    题解:我们使用一个二位数组dp[i][j]记录进行到第i个任务时,人组合为j时的最大和(这里的j我们用二进制的每位相应一个人). 详细见代码: #include <iostream> #i ...

  8. hdu 3091 Necklace 状态压缩dp *******

    Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total ...

  9. hdu 4628 Pieces 状态压缩dp

    Pieces Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

随机推荐

  1. ubuntu下面的某些软件安装

    1. python 下面的mysql驱动:不是在pip里面安装,执行下面命令 apt-get install python-mysqldb

  2. esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);

    esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx){ if (s_event_init_flag) { return ESP_ ...

  3. 1.jQuery入口函数

    <!--注意,如果需要对ie67兼容,我们可以使用原生低版本的jquery 比如说jquery-1.12.4.js--> <!DOCTYPE html> <html la ...

  4. ElasticSearch 从2.2升级到6.2.4所碰到的问题汇总

    1.ID的问题. 以前创建索引API直接用URL加索引Post过去就行了,或者在Kibana的开发工具中提交命令 PUT /customer?pretty 但是发现这样即使生成了索引,在ES中预览能看 ...

  5. 2D激光SLAM算法比较+cartographer

    Hector slam: Hector slam利用高斯牛顿方法解决scan-matching问题,对传感器要求较高. 缺点:需要雷达(LRS)的更新频率较高,测量噪声小.所以在制图过程中,需要rob ...

  6. Compile Groovy/Spock with GMavenPlus

    在之前的博文里曾使用GMaven插件编译Groovy/Spock,这次使用GMavenplus插件,更加方便. 具体步骤 1. 导入Spock和Groovy依赖 <dependency> ...

  7. sql查询字段中的值长度最大的记录

    SELECT max(length(字段)) FROM 表名;

  8. [八分之三的男人] POJ - 1741 点分治 && 点分治笔记

    题意:给出一棵带边权树,询问有多少点对的距离小于等于\(k\) 本题解参考lyd的算法竞赛进阶指南,讲解的十分清晰,比网上那些讲的乱七八糟的好多了 不过写起来还是困难重重(史诗巨作 打完多校更详细做法 ...

  9. [转] Vagrant入门

    [From] https://www.cnblogs.com/davenkin/p/vagrant-virtualbox.html 简单地说,Vagrant让我们可以通过代码的方式快速地.可重复地创建 ...

  10. Flutter Navigator operation requested with a context that does not include a Navigat

    如下直接在 MaterialApp 中使用 Navigator 是会报 Navigator operation requested with a context that does not inclu ...