Question:
Mining, at (0, 0)
N gold game time is t
N rows below
(X, y) Cost Val
In addition, if people and multiple pieces of gold are in the same line, they can only take the nearest gold first and take it in sequence, which is the same as the game.
And all vertices are in the 1 2 quadrant
Ideas:
We first group all the collocated points.
For each group of items, we can think that the cost of this item is the total cost of all items, and the value is the total value of all items.
In this way, the effects of First fetch and then fetch of each group of items can be eliminated, but one condition is that this group can only get one item at most, therefore, each status can only be obtained after this item or the original status.
Use the original state transfer, and then take the maximum value with the original state.
#include <iostream>#include <cmath>#include <algorithm>#include <cstdio>#include <map>#include <vector>typedef long long ll;template <class T>inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1;}template <class T>inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0');}const int N = 50000;using namespace std;typedef pair<int,int> pii;int t;void solve(int T, int V, int *d){ for(int j = t; j >= T; j --) { if(d[j] <= d[j-T] + V) d[j] = d[j-T] + V; }}int n, tim[250], val[250], x[250], y[250], d2[N], st[N];bool cmp(int a, int b){ return x[a]*x[a]+y[a]*y[a] < x[b]*x[b]+y[b]*y[b];}bool Coline(int a, int b){ return x[a]*y[b] == x[b]*y[a];}vector<int>G[205];int d[N], top;void input(){ for(int i = 1; i <= n; i++) { rd(x[i]); rd(y[i]); rd(tim[i]); rd(val[i]); } top = 0; for(int i = 1; i <= n; i++) { bool yes = false; for(int j = 0; j < top && false == yes; j++) if(Coline(i, G[j][0])) { G[j].push_back(i); yes = true; } if(yes)continue; G[top].clear(); G[top++].push_back(i); }}int main(){ int Cas = 1;; while(cin>>n>>t){ input(); memset(d, 0, sizeof d); for(int i = 0; i < top; i++) { sort(G[i].begin(), G[i].end(), cmp); memcpy(d2, d, sizeof d); memcpy(st, d, sizeof d); int V = 0, T = 0; for(int j = 0; j < G[i].size(); j++) { solve(T + tim[G[i][j]], V + val[G[i][j]], st); T += tim[G[i][j]]; V += val[G[i][j]]; for(int k = 0; k <= t; k++) d[k] = max(d[k], st[k]); if(T > t) break; memcpy(st, d2, sizeof d); } } printf("Case %d: %d\n", Cas++, d[t]); } return 0;}/*2 21 1 1 12 2 1 23 51 1 4 12 2 2 1001 3 4 73 8-1 1 4 21 1 5 12 2 2 1003 81 1 5 12 2 2 100-1 1 4 2*/
HDU 4341 gold miner group backpack Deformation