Test instructions:
The store sells n items, everything has a deadline, can be bought before the cut-off time, the store sells only one item per day. Ask for maximum profit.
Solution:
Use greed to do, my practice is to sort out the best value of the goods, and then put in Vis[j], said in the first day of sales of this commodity, and then traverse each item,
If one item is found to be higher than the value of a product sold on J days, move the value down to the previous day, and if the previous day is higher than the value of this low value commodity, continue to place a comparison on the front side, so repeat.
10000*10000, up to 1 seconds of multipoint time complexity, so no TL.
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std;
const int maxn=1e4+7; struct node {int p,d;}
A[MAXN];
int VIS[MAXN];
BOOL CMP (node B,node c) {return b.p>c.p;} int main () {int n;
while (~SCANF ("%d", &n)) {memset (vis,0,sizeof (VIS));
int max=0;
for (int i=0;i<n;i++) {scanf ("%d%d", &A[I].P,&A[I].D);
if (A[i].d>max) max=a[i].d;
} sort (a,a+n,cmp);
for (int i=0;i<n;i++) {int x=a[i].p; for (int j=a[i].d;j>=1;j--) {if (x>vis[j]) {int T=vi
S[J];
Vis[j]=x;
x=t;
}}} int sum=0;
for (int i=1;i<=max;i++) sum+=vis[i];
printf ("%d\n", sum); }}//* My approach is to sort the product that finds the maximum value and then put it in vis[j], which means selling the item in the J Day and then traversing each item, if one item is found to be sold in J days.The value of the commodity is also high, the value of the move to the previous day, if the day before the value of the commodity is higher than the value of the above, continue to place a comparison, so repeatedly.
10000*10000, up to 1 seconds of multi-point time complexity, so no TL. */