题意  多啦A梦有一个超电磁炮  然后要打死n堆敌人  在同一条射线上的敌人只有先打死前面的一堆才能打后面的一堆  给你打死某堆敌人需要的时间和这堆敌人的人数   问你在T0时间内最多打死多少个敌人

分组背包问题  先要把同一条射线上的敌人放到一个分组里  后面的敌人的时间和人数都要加上前面所有的  因为只有前面的都打完了才能打后面的  然后每组最多只能选择一个   判断共线用向量处理   然后去背包就行了

注意给你的样例可能出现t=0的情况   在分组时需要处理一下    被这里卡了好久

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 505;
int vis[N], dp[10086];struct enemy
{ll x, y;int t, w;
} e[N];bool cmp(enemy a, enemy b)  //按与原点的距离排序
{return a.x * a.x + a.y * a.y < b.x * b.x + b.y * b.y;
}bool aLine(int i, int j) //判断是否在同一条射线上·
{if(e[i].x * e[j].y == e[i].y * e[j].x)return e[i].x * e[j].x >= 0 &&  e[i].y * e[j].y >= 0;return 0;
}int main()
{ll x, y, x0, y0;int n, t0;while(~scanf("%lld%lld%d%d", &x0, &y0, &n, &t0)){for(int i = 0; i < n; ++i){scanf("%lld%lld%d%d", &x, &y, &e[i].t, &e[i].w);e[i].x = x - x0;e[i].y = y - y0;}sort(e, e + n, cmp);  //按与原点的距离排序vector<enemy> em[N];  //把在一条射线上的放到一个分组里memset(vis, 0, sizeof(vis));for(int i = 0; i < n; ++i){if(vis[i]) continue;  //i已经在别的组里了em[i].push_back(e[i]);for(int j = i + 1; j < n; ++j){if(!aLine(i, j)) continue;int k = em[i].size() - 1;vis[j] = 1;if(e[j].t == 0)  //把耗时为0的敌人放到上一个里{em[i][k].w += e[j].w;continue;}em[i].push_back(e[j]);em[i][k + 1].w += em[i][k].w;em[i][k + 1].t += em[i][k].t;}}memset(dp, 0, sizeof(dp)); //分组背包for(int i = 0; i < n; ++i){int k = em[i].size();for(int v = t0; v >= 0; --v)for(int j = 0; j < k && em[i][j].t <= v; ++j)dp[v] = max(dp[v], dp[v - em[i][j].t] + em[i][j].w);}printf("%d\n", dp[t0]);}return 0;
}

Doraemon's Railgun


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Doraemon's city is being attacked again. This time Doraemon has built a powerful railgun in the city. So he will use it to attack enemy outside the city.

There are N groups of enemy. Now each group is staying outside of the city. Group i is located at different (XiYi) and contains Wi soldiers. After T0 days, all the enemy will begin to attack the city. Before it, the railgun can fire artillery shells to them.

The railgun is located at (X0Y0), which can fire one group at one time, The artillery shell will fly straightly to the enemy. But in case there are several groups in a straight line, the railgun can only eliminate the nearest one first if Doraemon wants to attack further one. It took Ti days to eliminate group i. Now please calculate the maximum number of soldiers it can eliminate.

Input

There are multiple cases. At the first line of each case, there will be four integers, X0Y0NT0 (-1000000000 ≤ X0Y0 ≤ 1000000000; 1 ≤ N ≤ 500; 1 ≤ T0 ≤ 10000). Next N lines follow, each line contains four integers, XiYiTiWi (-1000000000 ≤ XiYi ≤ 1000000000; 0 ≤ TiWi ≤ 10000).

Output

For each case, output one integer, which is the maximum number of soldiers the railgun can eliminate.

Sample Input

0 0 5 10
0 5 2 3
0 10 2 8
3 2 4 6
6 7 3 9
4 4 10 2

Sample Output

20

ZOJ 3450 Doraemon's Railgun (DP·分组背包)相关推荐

  1. ZOJ - 3450 Doraemon's Railgun (dp)

    https://vjudge.net/problem/ZOJ-3450 题意 一座位落(X0,Y0)的城市将遭受n个敌人的摧残.现在我们手上有某科学的超电磁炮,每次攻击都是一条射线,对于共线的敌人,必 ...

  2. 牛客挑战赛34 A 能天使的愿望 (dp 分组背包)

    链接:https://ac.nowcoder.com/acm/contest/2271/A 来源:牛客网 题目描述 出题人寄给大家的一些闲话:参加了CSP-J/S 2019 的同学,考的都怎么样啊?不 ...

  3. hdu5148 树形dp,分组背包

    dp[i][j]表示以i为根节点的子树中选j个城市贡献边长的最小值,怎样由子树向上递推呢,子树是一个天然的组,dp[u][j]可以这样理解,u子树容量为j是由上一层dp[u][j-f]推出的,应用了滚 ...

  4. 【背包DP练习】洛谷 P5020货币系统 P1757通天之分组背包 P1064[NOIP2006 提高组]金明的预算方案 P5322 [BJOI2019]排兵布阵

    洛谷 P5020货币系统 https://www.luogu.com.cn/problem/P5020 思路是把货币从小到大排序,然后按顺序依次完全背包dp,每次dp检查i-1种面值的货币能不能凑出第 ...

  5. hdu 5148 树形dp,分组背包

    题目: 题目分析: 状态方程: dp[当前节点的标号][当前已经选取的城市数] 设已经选取的城市数是K 初始状态: dp[u][0] = dp[u][1] = 0 , 其他的将值设置为无穷大 树形转移 ...

  6. 动态规划dp(带模板题の超易懂版):01背包,完全背包,分组背包,多重背包,混合背包

    动态规划dp(带模板题の超易懂版):01背包,完全背包,分组背包,多重背包 01背包 && 完全背包 && 分组背包 の 视频教程:https://www.bilibi ...

  7. 洛谷:P4516 [JSOI2018] 潜入行动(树形dp、树上分组背包统计方案数)

    潜入行动 题意: 在树上每个点可以放置监控设备,监控该点周围的点(不包括该点),问刚好放置 k 个监控设备监控使得整棵树所有点都被监控的方案数是多少. 思路: 显然是个树形dp,k个监控自然联想分组背 ...

  8. ssl1377-竞赛真理【dp之分组背包】

    其实这题很简单,我也不想多讲,但没办法老师要我们发博客╭(╯^╰)╮ Description TENSHI在经历了无数次学科竞赛的失败以后,得到了一个真理:做一题就要对一题!但是要完全正确地做对一题是 ...

  9. 分组背包----HDU1712 ACboy needs your help

    很简单的一道分组背包入门问题.不多解释了. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring&g ...

最新文章

  1. Django实战之美化页面
  2. Design Pattern - Composite(C#)
  3. markdown常用操作(特殊字符显示、换行、字体颜色和大小、图片位置和大小)
  4. 使用ffmpeg循环推流(循环读取视频文件)推送RTMP服务器的方法
  5. (转)Linux内核参数之arp_ignore和arp_announce
  6. 尝鲜!.NET5实操之docker+k8s,这10个坑,你不得不知!
  7. php cookie 加密解密,php实现cookie加密的方法
  8. 报表选型除了看开发难易,还要看运维省不省心
  9. 微信小程序之自定义toast弹窗
  10. 《编写可读代码的艺术》---变量和可读性
  11. 【SQL Server】 SQL Server Management Studio不允许保存更改,组织保存要求解决方案
  12. win10的js文件-bat脚本-开启移动热点
  13. LINUX SHELL使用变量控制循环
  14. html判断隐藏显示,javascript如何判断元素是否可见?
  15. Microsoft Word 2010 - 符号 / 特殊符号
  16. 实时共享白板_使用Froala文本编辑器构建实时协作白板-第1部分。
  17. c++取模运算/求余运算
  18. 关于字段超长导致的插入错误的提示信息(value too long for type character varying)
  19. Apache Spark源码走读(九)如何进行代码跟读使用Intellij idea调试Spark源码
  20. 大学期间技术学习方面最有成就感的事?

热门文章

  1. java计算机毕业设计计算机类专业考研交流学习平台MyBatis+系统+LW文档+源码+调试部署
  2. 本科3-4万、硕士6万、博士8万!杭州这个区发力引人
  3. 香港理工计算机世界排名,香港理工大学这四个专业是全球百强
  4. 18年_PMO_实践
  5. 汇川AM401非标准协议通讯socket_client
  6. matlab箱形图_使用javascript可视化世界幸福来构建箱形图
  7. 7-3 JAVA-水仙花数 (20 分)
  8. 单片机程序烧录的3种方式(ISP、ICP、IAP)是什么?
  9. Delphi数据库处理组件BDE、ADO、InterBase和dbExpress详细说明
  10. 迷宫问题寻找最短路径(BFS)