20191111luogu3961 Gold Miner | slope | grouping backpack dp

luogu3961 Gold Miner

Meaning of the questions:

From the (0,0) coordinate break points to take gold, gold (x, y), take the time required for the gold t, the value of v, the origin of the gold on the same wire you need to take in order to get back the recent, the maximum value within the required time T can get

dp:

First pretreatment, the origin point is determined for each connection slope, slope and origin by the distance from small to large, the same slope points are divided into a group, this group is selected from the pretreated article time required for the i-th and the resulting value can be regrouping backpack dp

time complexity:

O(nt)

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 #define db double
 5 struct node
 6 {
 7     int x,y,t,v;
 8     db k;
 9 }a[2005];
10 bool cmp(node x,node y)
11 {
12     if(x.k == y.k)return x.y < y.y;
13     return x.k < y.k;
14 }
15 int N,T,cnt;
16 int num[2005],v[2005][2005],t[2005][2005];
17 int f[40005];
18 int main()
19 {
20     scanf("%d%d",&N,&T);
21     for(int i= 1;i <= N;i ++)
22     {
23         scanf("%d%d%d%d",&a[i].x,&a[i].y,&a[i].t,&a[i].v);
24         A [I] = .K (DB) ((DB) A [I] .y / (DB) A [I] .x);
 25      }
 26 is      Sort (A + . 1 , A + . 1 + N, CMP);
 27      for ( int I = . 1 ; I <= N; I ++ )
 28      {
 29          IF (! A [I] .K = A [I - . 1 ] .K) CNT ++ ;
 30          NUM [CNT] ++ ; // If you do not write on the outside will be 80? ? ? ? ? 
31 is          V [CNT] [NUM [CNT]] = V [CNT] [NUM [CNT] - . 1 ] + A [I] .v;
 32          T [CNT] [NUM [CNT]] = T [CNT] [NUM [CNT] - . 1 ] + A [I] .T;
33     }
34     for(int i = 1;i <= cnt;i ++)
35         for(int j = T;j >= t[i][1];j --)
36             for(int k = 1;k <= num[i];k ++)
37                 if(j >= t[i][k])f[j] = max(f[j],f[j - t[i][k]] + v[i][k]);
38     printf("%d\n",f[T]);
39     return 0;
40 }

 

Guess you like

Origin www.cnblogs.com/djfuuxjz/p/11836729.html