Pebbles(hdu 2167)
题意:给定一个N*N的方格,让你在里面取出一些数使其和最大,要求每一个数不能与其相邻的8个数同时取出。
/*
和hdu1565差不多,只不过在更新的时候考虑斜上方的格子对该格子的影响。
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 16
using namespace std;
int dp[N][<<N],a[N][N],n,m;
char ch[N*];
void dfs(int s,int ss,int y,int x,int sum){
if(y>n-){
dp[x+][ss]=max(dp[x+][ss],dp[x][s]+sum);
return;
}
int flag=;
if(s&(<<y)) flag=;
if(y>&&(s&(<<y-))) flag=;
if(y<n-&&(s&(<<y+))) flag=;
if(!flag) dfs(s,ss|(<<y),y+,x,sum+a[x+][y]);
dfs(s,ss,y+,x,sum);
}
void work(){
for(int i=;i<=n;i++)
for(int j=;j<n;j++)
scanf("%d",&a[i][j]);
for(int i=;i<n;i++)
for(int j=;j<(<<n);j++)
dfs(j,,,i,);
int ans=;
for(int i=;i<(<<n);i++)
ans=max(ans,dp[n][i]);
printf("%d\n",ans);
}
int main(){
while(gets(ch)){
memset(dp,,sizeof(dp));
int len=strlen(ch);n=;
if(!len) continue;
for(int i=;i<len;i+=)
a[][n++]=(ch[i]-'')*+ch[i+]-'';
work();
}
return ;
}
Pebbles(hdu 2167)的更多相关文章
- 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)
//1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...
- Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...
- 2013 多校联合 F Magic Ball Game (hdu 4605)
http://acm.hdu.edu.cn/showproblem.php?pid=4605 Magic Ball Game Time Limit: 10000/5000 MS (Java/Other ...
- (多线程dp)Matrix (hdu 2686)
http://acm.hdu.edu.cn/showproblem.php?pid=2686 Problem Description Yifenfei very like play a num ...
- War Chess (hdu 3345)
http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) geometry(hdu 5605)
geometry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- 2013多校联合2 I Warm up 2(hdu 4619)
Warm up 2 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
随机推荐
- javaweb基础(9)_Servlet生成验证码图片
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- java基础—super关键字
一.super关键字
- An Intuitive Explanation of Convolutional Neural Networks
https://ujjwalkarn.me/2016/08/11/intuitive-explanation-convnets/ An Intuitive Explanation of Convolu ...
- 【上下界网络流】bzoj2502: 清理雪道
模型:无源汇有上下界可行流 LJN:模板题吧 Description 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的 ...
- 【细节题 离线 树状数组】luoguP4919 Marisa采蘑菇
歧义差评:但是和题意理解一样了之后细节依然处理了很久,说明还是水平不够…… 题目描述 Marisa来到了森林之中,看到了一排nn个五颜六色的蘑菇,编号从1-n1−n,这些蘑菇的颜色分别为col[1], ...
- (69)zabbix监控惠普打印机
假设公司有多个楼层或者分布在不同楼,打印机自然分布很广泛,打印机缺少油墨或者卡纸了,都需要员工找IT部门.我们使用zabbix对打印机进行监控,一旦缺少油墨,zabbix发出报警,it人员能够及时更换 ...
- 01、Linux介绍
一. Linux介绍 Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的UNIX工具软件.应用程序和 ...
- Buffered Channels and Worker Pools
原文链接:https://golangbot.com/buffered-channels-worker-pools/ buffered channels 带有缓冲区的channel 只有在缓冲区满之后 ...
- CUB reduce errorinvalid configuration argument
解决CUB reduce errorinvalid configuration argument问题 在写TensorFlow代码时遇到报错 CUB reduce errorinvalid confi ...
- 用Comparator排序和分组
Test实体 import java.util.Objects; /** * @author gallen * @description * @date 2018/11/16 * @time 18:5 ...