[hdu2167]Pebbles
来自FallDream的博客,未经允许,请勿转载,谢谢。
给定一个方阵,你要取出一些数字,满足没有两个格子八联通相邻的前提下和最大,求这个和
n<=15
插头dp,保存轮廓线以及目前转移点左上方那个格子的状态,枚举格子转移即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#define MN 15
using namespace std;
inline int read()
{
int x = , f = ; char ch = getchar();
while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x * f;
} char st[];
int a[MN+][MN+],m,f[][<<]; int Strread()
{
int top=,j=;
for(int i=;st[i]==' '||(st[i]>=''&&st[i]<='');++i)
if(st[i]==' ') a[][++top]=j,j=;
else j=j*+st[i]-'';
return a[][++top]=j,top;
}
inline void R(int&x,int y){y>x?x=y:;}
int main()
{
while(cin.getline(st,))
{
m=Strread();if(m==&&a[][]==) continue;
for(int i=;i<=m;++i)
for(int j=;j<=m;++j)
a[i][j]=read();
memset(f,,sizeof(f));
int now=,pre=;
for(int i=;i<=m;++i)
for(int j=;j<=m;++j,swap(now,pre),memset(f[now],,sizeof(f[now])))
for(int k=;k<<<(m+);++k)
{
R(f[now][(k&((<<m)-(<<(j-))-))|((k&(<<(j-)))?(<<m):)],f[pre][k]);
if((j==||(!((k&(<<m)))&&!(k&(<<(j-)))))&&!(k&(<<(j-)))&&(j==m||!(k&(<<j))))
R(f[now][(k&((<<m)-))|(<<(j-))|((k&(<<(j-)))?(<<m):)],f[pre][k]+a[i][j]);
}
int ans=;
for(int i=;i<<<(m+);++i) ans=max(ans,f[pre][i]);
cout<<ans<<endl;
}
return ;
}
[hdu2167]Pebbles的更多相关文章
- HDU2167 Pebbles(状压DP)
题目给一张n×n的格子,每个格子都有数字,要从格子中取若干个数字,八个方向相邻的数字不能一起取,问取的数字最大和是多少. 从第一行一行一行看下去,可以发现第1行取哪几列只会影响到第2行,第3行后面的一 ...
- Pebbles(hdu2167)
Pebbles Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- codeforces 507B. Painting Pebbles 解题报告
题目链接:http://codeforces.com/problemset/problem/509/B 题目意思:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色 ...
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...
- Pebbles
Pebbles Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- UVALive 7461 Separating Pebbles (计算几何)
Separating Pebbles 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/H Description http://7 ...
- B. Painting Pebbles
B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论
1982: [Spoj 2021]Moving Pebbles Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 130 Solved: 88[Submi ...
- cf509B Painting Pebbles
B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- python3变量和数据类型
变量和数据类型 知识点 python 关键字 变量的定义与赋值 input() 函数 字符串的格式化 实验步骤 每一种编程语言都有它们自己的语法规则,就像我们所说的外语. 1. 关键字和标识符 ...
- git基本用法
基本用法(下) 一.实验说明 本节实验为 Git 入门第二个实验,继续练习最常用的git命令. 1.1 实验准备 在进行该实验之前,可以先clone一个练习项目gitproject ...
- EXT3文件系统误删除导致文件系统中的邮件丢失恢复方法
一.故障描述 由8块盘组成的RAID5, 上层是EXT3文件系统,由于误删除导致文件系统中的邮件丢失 二.镜像磁盘为防止数据恢复过程中由于误操作对原始磁盘造成二次破坏, 使用winhex软件为每块磁盘 ...
- 构建微服务开发环境8————Hello 微服务
[内容指引] 1.用IDEA打开微服务项目; 2.更新Maven依赖: 3.IntelliJ IDEA JDK配置; 4.修改代码: 5.运行微服务: 6.将代码变更提交到Github. 经过前面的努 ...
- Windows Powershell脚本执行
在cmd下执行powershell进入shell模式: 变量定义:$i = 10 $a = ifconfig | findstr "192" Windows下的命令都可以执行如: ...
- EasyUI Datagrid 分页的情况下实现点击表头的小三角图标对数据库中所有数据重新排序
说明一下: 当点击 datagrid 表头某一列的小三角图标时,easyui 本身是有排序的,但是在当我们对 datagrid 进行了分页的情况下,点击排序只是对当前页的数据进行排序,而需求需要我对数 ...
- Python内置函数(48)——__import__
英文文档: __import__(name, globals=None, locals=None, fromlist=(), level=0) This function is invoked by ...
- Python-基础学习-Day1
1 Python介绍 1.1 Python 是一门什么样的语言? python是一门动态解释性的强类型定义语言. 编译型的特点:可一致性差,运行速度快. 解释型的特点:边执行边解释,速度慢 1.2 P ...
- 使用Putty实现windows向阿里云的Linux云服务器上传文件
1.首先获取PSCP工具 PuTTY小巧方便.但若需要向网络中的Linux系统上传文件,则可以使用PuTTY官方提供的PSCP工具来实现上传.PSCP是基于ssh协议实现. 可以点击这里下载 2.启动 ...
- Python 爬取淘宝商品信息和相应价格
!只用于学习用途! plt = re.findall(r'\"view_price\"\:\"[\d\.]*\"',html) :获得商品价格和view_pri ...