ZOJ 3450 Doraemon ' s Railgun (DP Group backpack)

Source: Internet
Author: User
Tags railgun

Test instructions A dream has a super electromagnetic gun and then to kill N heap enemy enemies on the same ray of the enemy only to kill the front of a pile to fight the back of a pile of time and the number of enemies to beat you to kill a lot of enemies asked how many enemies you killed in T0 time

group knapsack problem first put the enemy on the same ray into a group. The time and the number of enemies in the rear must be preceded by all because only the front is finished to hit the back and then each group can only select one judgment collinear with vector processing then go to the backpack.

Note that the sample that is given to you may appear t=0 in the case of a group that needs to be dealt with. It's been stuck here for a long time.

#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)//Sort by distance from Origin {return a.x * a.x + a.y * A.Y < b.x * b.x + b.y * B.Y;} BOOL ALine (int i, int j)//judgment on the same ray ·    {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, &AMP;E[I].W);            e[i].x = x-x0;        E[i].y = y-y0;  } sort (E, E + N, CMP);  Sort by the distance from the origin vector<enemy> Em[n];        Put a ray in a group memset (VIS, 0, sizeof (VIS)); for (int i = 0; i < n; ++i) {if (Vis[i]) CONtinue;            I have been in other groups 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)//put the 0-time enemy in the previous {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));            Group Backpack 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 have built a powerful railgun in the city. So he'll use it to attack enemy outside the city.

There is N groups of enemy. Now all group is staying outside of the city. Group I is located at different (X i , Y i ) and contains W i soldiers. After days T0 , all the enemy would begin to attack the city. Before it, the railgun can fire artillery shells to them.

The Railgun is located at ( X0 , Y0 ), which can fire one group at one time, the artillery shell would fly straightly to The enemy. But in case there is several groups in a straight line, the railgun can only eliminate the nearest one first if Doraemon Wants to attack further one. It took T days to i eliminate group I. Now calculate the maximum number of soldiers it can eliminate.

Input

There is multiple cases. At the first line of all case, there'll be is four integers,, X0 Y0 , N, T0 ( -1000000000≤ X0 , Y0 ≤ 1000000000; 1 ≤ N ≤ 500; 1 ≤ T0 ≤10000).  Next N lines follow, each line contains four integers, X i , Y i , T i , W i ( -1000000000≤ X i , Y i ≤ 1000000000; 0≤ T i , w i ≤10000).

Output

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

Sample Input
0 0 5 100 5 2 30 10 2 83 2 4 66 7 3 94 4 10 2
Sample Output
20



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ZOJ 3450 Doraemon ' s Railgun (DP Group backpack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.