(中等) POJ 3034 Whac-a-Mole,DP。
2015-07-21 10:15
459 查看
Description
View Code
// ━━━━━━神兽出没━━━━━━ // ┏┓ ┏┓ // ┏┛┻━━━━━━━┛┻┓ // ┃ ┃ // ┃ ━ ┃ // ████━████ ┃ // ┃ ┃ // ┃ ┻ ┃ // ┃ ┃ // ┗━┓ ┏━┛ // ┃ ┃ // ┃ ┃ // ┃ ┗━━━┓ // ┃ ┣┓ // ┃ ┏┛ // ┗┓┓┏━━━━━┳┓┏┛ // ┃┫┫ ┃┫┫ // ┗┻┛ ┗┻┛ // // ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy // Created Time : 2015年07月20日 星期一 20时03分48秒 // File Name : 3034.cpp #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; const int MaxN=42; int dp[MaxN][MaxN][15]; int N,D,M; int map1[MaxN][MaxN][15]; int gcd(int a,int b) { if(!a) return b; return gcd(b%a,a); } int sum(int x1,int y1,int x2,int y2,int t) { int dx=x2-x1,dy=y2-y1; int temp=gcd(abs(dx),abs(dy)); int ret=0; if(temp) { dx/=temp; dy/=temp; } for(int i=0;i<=temp;++i) ret+=map1[x1+i*dx+5][y1+i*dy+5][t]; return ret; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int x,y,t; int maxn; while(~scanf("%d %d %d",&N,&D,&M) && N+D+M) { memset(dp,0,sizeof(dp)); memset(map1,0,sizeof(map1)); for(int i=1;i<=M;++i) { scanf("%d %d %d",&x,&y,&t); ++map1[x+5][y+5][t]; } for(int i=1;i<=10;++i) for(x=-5;x<N+6;++x) for(y=-5;y<N+6;++y) { maxn=0; for(int x1=-5;x1<N+6;++x1) for(int y1=-5;y1<N+6;++y1) if(D*D>=(x-x1)*(x-x1)+(y-y1)*(y-y1)) maxn=max(maxn,dp[x1+5][y1+5][i-1]+sum(x,y,x1,y1,i)); dp[x+5][y+5][i]=maxn; } maxn=0; for(int i=-5;i<N+6;++i) for(int j=-5;j<N+6;++j) maxn=max(maxn,dp[i+5][j+5][10]); printf("%d\n",maxn); } return 0; }
View Code
相关文章推荐
- CISCO IOS 分类
- 基础数据结构priority_queue用法
- C#中Cookie之存储对象
- Opengl ES IBO(索引缓冲区) VBO(顶点缓冲区)创建一个立方体
- HDU 3530 Subsequence(单调队列维护)
- 无线网无法上网,ping的时候显示hardware error错误的解决办法
- Python 线程和定时器
- 学习笔记10:Scala单例对象、伴生对象
- Android性能调优之内存篇
- 进程有哪几种基本状态,在一个系统中为什么必须区分出这几种状态?
- js 封装的函数 总结
- 可伸缩性/可扩展性(Scalable/scalability)
- Swift2.0语言教程之类的属性
- Linux系统一些常用系统命令
- 第八节
- leetcode[118]:Pascal's Triangle
- 使用Paros监控iPhone发出的HTTP请求
- Android访问权限大全
- hadoop-2.2.0安装方法详解
- php之数据类型自动转换