[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 ...
随机推荐
- 清华集训2015 V
#164. [清华集训2015]V http://uoj.ac/problem/164 统计 描述 提交 自定义测试 Picks博士观察完金星凌日后,设计了一个复杂的电阻器.为了简化题目,题目中的常数 ...
- lodash源码分析之获取数据类型
所有的悲伤,总会留下一丝欢乐的线索,所有的遗憾,总会留下一处完美的角落,我在冰峰的深海,寻找希望的缺口,却在惊醒时,瞥见绝美的阳光! --几米 本文为读 lodash 源码的第十八篇,后续文章会更新到 ...
- ELK学习总结(2-6)elk的mapping
1.什么是映射 映射:创建索引的时候,预先定义字段的类型及相关属性 作用:这样会让索引建立的更加细致和完善,如:是否存储.使用何种分析器.重要级别 分类:静态映射和动态映射 2.字段类型:string ...
- apigw鉴权分析(1-2)腾讯开放平台 - 鉴权分析
一.访问入口 http://wiki.open.qq.com/wiki/%E8%85%BE%E8%AE%AF%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0%E7%AC%AC% ...
- ehcache.xml 属性大全
属性大全 name:缓存名称. maxElementsInMemory:缓存最大个数. eternal:对象是否永久有效,一但设置了,timeout将不起作用. timeToIdleSeconds:设 ...
- 云服务器ECS优惠券 阿里云 ecs 5折优惠码 阿里云5折优惠码 阿里云5折推荐码 阿里云优惠码 阿里云的5折优惠券 阿里云服务器购买优惠码 服务器购买优惠码
阿里云代金券 | 阿里云优惠券云服务器ECS,就是阿里云服务器,大家一定要清楚.云服务器ECS优惠券官方领取优惠页面:https://promotion.aliyun.com/ntms/act/amb ...
- 使用net.sf.cssbox实现网页截图
需要引用包,在pom.xml中添加引用: <dependency> <groupId>net.sf.cssbox</groupId> <artifactId& ...
- OptionMenu选项菜单
#选项菜单 from tkinter import * root = Tk() variable=StringVar() variable.set('one') w = OptionMenu(root ...
- jquery的ajax全局事件详解
jquery在ajax方面是非常强大和方便的,以下是jquery进行ajax请求时方法模板: $.ajax({ type: "get", url: "" ...
- border三角形阴影(不规则图形阴影)和多重边框的制作
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 1. border的组合写法 border:border-width border-style borde ...