博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 2167 Pebbles
阅读量:5794 次
发布时间:2019-06-18

本文共 4062 字,大约阅读时间需要 13 分钟。

Pebbles

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 777 Accepted Submission(s): 426
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
2007 ACM-ICPC Pacific Northwest Region
Recommend
lcy

1 //484MS    2808K    1941 B    C++      2 /* 3      4     题意: 5         给出n*n个数,求最大的不相邻的数的和(对角也算)   6      7     状态压缩:  8         dp[i][j]表示前i行中状态j的最优策略  9         这题和 hdu1565 类似,也是方格取数问题,我采用了一样的解法,10     唯一的小变形是在判断相邻行剪得判断,要加左移和右移的判断(判断对角),11     其他和 hdu1565 差不多 12 13 */14 #include
15 #include
16 int dp[20][1<<15];17 int g[20][20];18 int s[2000];19 char c[100];20 int Max(int a,int b)21 {22 return a>b?a:b;23 }24 int judge(int x) //判断 25 {26 int end=0;27 while(x){28 if(end && (1&x)) return 0;29 end=1&x;30 x>>=1;31 }32 return 1;33 }34 void init() //预处理符合条件的状态 35 {36 memset(s,0,sizeof(s));37 int k=0;38 for(int i=0;i<(1<<15);i++)39 if(judge(i)) s[k++]=i;40 //printf("%d\n",k); //k=159741 }42 int main(void)43 {44 init();45 while(gets(c)) 46 {47 int len=strlen(c);48 int n=0,t=0;49 for(int i=0;i
='0' && c[i]<='9'){52 t=t*10+c[i]-'0';53 }else{54 g[0][n++]=t;t=0;55 }56 }57 g[0][n++]=t;58 memset(dp,0,sizeof(dp));59 int n0=1<
>1)))) //小变形,主要是处理对角情况 78 dp[i][j]=Max(dp[i][j],temp+dp[i-1][k]);79 maxn=Max(maxn,dp[i][j]);80 }81 }82 printf("%d\n",maxn);83 c[0]=getchar(); //后面两个用于处理换行符和空行 84 gets(c); 85 }86 return 0;87 }

 

转载于:https://www.cnblogs.com/GO-NO-1/articles/3369863.html

你可能感兴趣的文章
201521123009 《Java程序设计》第1周学习总结
查看>>
年终述职--常见问题分析解答
查看>>
在mui中创建aJax来请求数据..并展示在页面上
查看>>
spring 之AOP
查看>>
总结 15/4/23
查看>>
Windows 7环境下网站性能测试小工具 Apache Bench 和 Webbench使用和下载
查看>>
C#常见错误解决方法
查看>>
安装cnpm (npm淘宝镜像)
查看>>
Java 面向对象(基础) 知识点总结I
查看>>
读书笔记《自控力》
查看>>
区域生长算法
查看>>
hive学习2(Navicat连接hive)
查看>>
getResourceAsStream的3种路径配置
查看>>
switch语句小练习
查看>>
组合逻辑电路
查看>>
POP-一个点击带有放大还原的动画效果
查看>>
UE4材质是什么样的机制
查看>>
使用QTP录制自带Flight小实例
查看>>
Loadrunner脚本编程(4)-数据类型操作和字符串操作
查看>>
STL 算法
查看>>