poj3034Whac-a-Mole(dp)
状态转移好想 不过有坑 大家都犯的错误 我也会犯 很正常
就是锤子可以移到n*n以外 要命的是我只加了5 以为最多不会超过5 WA了N久 才想到 上下两方向都可以到5 所以最多加10
以时间和坐标进行DP
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define N 1010
#define M 32
struct node
{
int x[N],y[N];
}f[M][M];
int o[][M][M];
int dp[][M][M];
int n,nu[M][M];
int dis(int x1,int y1,int x2,int y2)
{
if(x1<||x1>=n+||y1<||y1>=n+)
return -;
int s;
s = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
return s;
}
int main()
{
int i,j,g,k,d,kk,m;
while(scanf("%d%d%d",&n,&d,&m)!=EOF)
{
if(n==&&d==&&m==)
break;
memset(dp,,sizeof(dp));
memset(o,,sizeof(o));
memset(nu,,sizeof(nu));
int maxz = ;
int a,b,c;
for(i = ; i <= m ; i++)
{
scanf("%d%d%d",&a,&b,&c);
o[c][a+][b+] =;
maxz = max(maxz,c);
}
int ans=;
for(i = ; i < n+ ; i++)
for(j = ;j < n+ ; j++)
{
int po = ;
for(k = -d; k <= d; k++)
for(kk = -d; kk <= d ; kk++)
{
int tx = i+k;
int ty = j+kk;
if(dis(tx,ty,i,j)!=-&&dis(tx,ty,i,j)<=d*d)
{
po++;
f[i][j].x[po] = tx;
f[i][j].y[po] = ty;
nu[i][j] = po;
}
}
}
for(i = ;i <= maxz ; i++)
for(j = ; j < n+ ; j++)
for(g = ; g < n+ ; g++)
for(k = ; k <= nu[j][g] ; k++)
{
int tx = f[j][g].x[k];
int ty = f[j][g].y[k];
int x1 = min(tx,j),x2 = max(tx,j);
int y1 = min(ty,g),y2 = max(ty,g);
int num = ;
for(kk = x1; kk <= x2 ; kk++)
for(int mm = y1 ; mm <= y2 ; mm++)
{
if((ty-g)*(kk-j)==(tx-j)*(mm-g)&&o[i][kk][mm])
num++;
}
dp[i][tx][ty] = max(dp[i][tx][ty],dp[i-][j][g]+num);
ans = max(ans,dp[i][tx][ty]);
}
printf("%d\n",ans);
}
return ;
}
poj3034Whac-a-Mole(dp)的更多相关文章
- BZOJ4849[Neerc2016]Mole Tunnels——模拟费用流+树形DP
题目描述 鼹鼠们在底下开凿了n个洞,由n-1条隧道连接,对于任意的i>1,第i个洞都会和第i/2(取下整)个洞间有一条隧 道,第i个洞内还有ci个食物能供最多ci只鼹鼠吃.一共有m只鼹鼠,第i只 ...
- (中等) POJ 3034 Whac-a-Mole,DP。
Description While visiting a traveling fun fair you suddenly have an urge to break the high score in ...
- Codeforces Round #271 (Div. 2) D 简单dp
D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input ...
- Mole and Abandoned Mine
Mole and Abandoned Mine n点m条边的无向图,删除第i条边花费c[i],问1到n只有一条路径时所需要的最小花费? \(2\le n\le 15\) . 我又A掉了一道zzs的题啦 ...
- Codeforces Round #271 (Div. 2) D Flowers【计数dp】
D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input ...
- BZOJ 1207 [HNOI2004]打鼹鼠:dp【类似最长上升子序列】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1207 题意: 有一个n*n的网格,接下来一段时间内会有m只鼹鼠出现. 第i只鼹鼠会在tim ...
- Codeforces Round #271 (Div. 2) D.Flowers DP
D. Flowers We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, ...
- Codeforces 474D Flowers (线性dp 找规律)
D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
随机推荐
- Cassandra1.2文档学习(12)—— hint机制
参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/dml/dml_about_ ...
- php 操作mongodb
在这里首先说一下mongo 客户端安装完成有时会启动失败 这里解决办法就是 删除 D:\mongodb\db 下的 mongod.lock文件即可 再重新启动 首先下载mongodb php扩 ...
- 【Delphi】窗体阴影
procedure TForm1.FormCreate(Sender: TObject); begin SetClassLong(Handle, GCL_STYLE, GetClassLong(Han ...
- 直接下载完整chrome浏览器的方法
目前通过下吗的链接可以获得独立的安装包. http://www.google.com/chrome/eula.html?standalone=1&hl=zh-CN
- 由底层和逻辑说开去--c++之引用的深入剖析
在学c++的时候 我遇到的第一个问题就是这个引用,引用是什么东西,我的c++启蒙教科书是c++ primer plus,这本书上说的是:引用是已定义变量的别名,可以使用这个引用来表示这个变量:每当看到 ...
- php校验
//校验function filters($grams){ if(get_magic_quotes_gpc()) { $resgram = trim($grams); ...
- @properties指针说明
在iOS开发过程中,属性的定义往往与retain, assign, copy有关,我想大家都很熟悉了,在此我也不介绍,网上有很多相关文章. 现在我们看看iOS5中新的关键字strong, weak, ...
- easy ui 表单ajax和from两种提交数据方法
说明: ①ajax在表单提交时需要将所有表单的控件的数据一一获取并赋值传到后台 ②form在提交时,只要给控件加name属性,在提交时就可以将表单数据提交到后台,不需要一一获取再进行赋值. ajax ...
- 【android-cocos2d-X2.2 环境配置】在Mac下搭建Cocos2d-X-android开发环境!
仅用于cocos2d-X2.2--cocos2d-X3.4 原文地址:http://blog.csdn.net/dingkun520wy/article/details/17097593 (1)下载 ...
- java se doc
J2SE 5.0 Performance White Paper http://www.oracle.com/technetwork/java/5-136747.html Java Tuning Wh ...