CodeForces 30C Shooting Gallery 简单dp

题目链接:点击打开链接

给定n个气球

下面n行 x y t val 表示气球出现的坐标(x,y) 出现的时刻t,气球的价值val

枪每秒移动1个单位的距离

问:

射击的最大价值,开始时枪瞄准的位置任意。

思路:

dp一下。。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>
#include <map>
using namespace std;
#define ll long long
#define N 2005
ll n;
struct node{
	ll x,y,t;
	double val;
}a[N];
bool cmp(node aa, node bb){
	return aa.t<bb.t;
}
ll dist(node aa, node bb){
	return (aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y);
}
ll dis[N][N];
double dp[N];
int main(){
	ll i,j,u,v;
	while(cin>>n){
		for(i = 1; i <= n; i++)
			cin>>a[i].x>>a[i].y>>a[i].t>>a[i].val;
		sort(a + 1, a + 1 + n, cmp);
		for(i = 1; i <= n; i++) {
			for(j = i+1; j <= n; j++)
				dis[i][j] = dis[j][i] = dist(a[i],a[j]);
		}
		for(i = 1; i <= n; i++) {
			dp[i] = a[i].val;
			for(j = 1; j < i; j++) {
				if(dis[i][j] > ((a[i].t-a[j].t)*(a[i].t-a[j].t)))
					continue;
				dp[i] = max(dp[i], dp[j]+a[i].val);
			}
		}
		double ans = 0;
		for(i = 1; i <= n; i++)
			ans = max(ans, dp[i]);
		printf("%.10lf\n",ans);
	}
	return 0;
}

CodeForces 30C Shooting Gallery 简单dp

时间: 2024-07-30 10:17:32

CodeForces 30C Shooting Gallery 简单dp的相关文章

Codeforces 456C - Boredom(简单DP)

Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single s

Codeforces - 909C - Python Indentation - 简单dp

好像以前做过,但是当时没做出来,看了题解也不太懂. 一开始以为只有上面的for有了循环体,这里的statement就可以随便放,但其实并不是这样,statement的位置会取消比它缩进更多或相等的for的可append性.所以设计dp顺序的时候要用dp[i][j]表示第i行剩余可选for循环数量为j的选法数.那么递推公式也不难(才怪),看看代码就好了. 有几个可以优化的,一个是滚动数组,另一个是线性求前缀和然后均摊O(1)减少一个维度的时间复杂度. 注意读入%c之前要加一个空格来过滤前面还保留在

CodeForces 22B Bargaining Table 简单DP

题目很好理解,问你的是在所给的图中周长最长的矩形是多长嗯用坐标(x1, y1, x2, y2)表示一个矩形,暴力图中所有矩形易得递推式:(x1, y1, x2, y2)为矩形的充要条件为: (x1, y1, x2, y2) 和 (x1, y1, x2, y2)为合法矩形,即全部为0 Point(x2, y2) 为 0 当然对X1 == X2这种特殊情况需要特殊判断一下. Source Code: //#pragma comment(linker, "/STACK:16777216")

Codeforces 41D Pawn 简单dp

题目链接:点击打开链接 给定n*m 的矩阵 常数k 下面一个n*m的矩阵,每个位置由 0-9的一个整数表示 问: 从最后一行开始向上走到第一行使得路径上的和 % (k+1) == 0 每个格子只能向或走一步 求:最大的路径和 最后一行的哪个位置作为起点 从下到上的路径 思路: 简单dp #include <cstdio> #include <algorithm> #include<iostream> #include<string.h> #include &

codeforces Gym 100500H A. Potion of Immortality 简单DP

Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Noura Boubou is a Syrian volunteer at ACM ACPC (Arab Collegiate Programming Contest) since 2011. She graduated from Tishreen Un

Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. 简单dp,dp[i]表示取i时zui最大和为多少,方程为dp[i] = max(dp[i - 1] , dp[i - 2] + cont[i]*i). 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef __int64 LL;

POJ 3250 Bad Hair Day 简单DP 好题

Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a sp

hdu1207 汉诺塔II 简单dp

本文出自:http://blog.csdn.net/svitter 题意:汉诺塔,多了一根柱子,问你寻找最快的移动次数. dp [ n ] = dp [ n - j ] * 2 + pow( 2, j ) - 1; 就是把j个汉诺塔移到一根上dp[ n - j ],然后就是普通的汉诺塔问题,即2^n - 1次移动, 然后把剩下的移动过去dp [ n - j ]. 注意pow(2, j )可能超出long long int范围.写二的次方的时候也可用移位算法. #include <iostream

POJ1088:滑雪(简单dp)

题目链接:  http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一下序,因为只能高度递减才能滑行.之后就很简单了,就是简单DP. 即:要求的滑坡是一条节点递减并依次相邻的最长路径,可以先根据高度将所有的点进行排序,在i点的时候,遍历0~i-1个点(升序排序,i前面的点的高度一定小于等于i),取相邻点间的大的路径长度 代码如下: #include <iostream