Test Instructions: Susake to complete n tasks, there is a total of V days, each task has a start time and termination time, value of w[i], the maximum value input1Ten 51 5 -3 Ten Ten5 Ten -1 4 26 A 266Output102#include<stdio.h>#include<string.h>#include<algorithm>using namespacestd;structnode{intstart; intend; intW;}; Node a[1111];intdp[1111];intComp (node x, node Y) {returnX.end < y.end?1:0;}intMainintargcChar*argv[]) { intT, V, N, si, ei, WI; scanf ("%d", &t); while(t--) {memset (A,0,sizeof(a)); intK =0; scanf ("%d%d", &v, &N); for(inti =1; I <= N; i++) {scanf ("%d%d%d", &si, &ei, &WI); if(Si >=1&& ei <=v) {k++; A[k].start=si; A[k].end=ei; A[K].W=WI; }} sort (a+1, A + K +1, comp); Memset (DP,0,sizeof(DP)); for(inti =1; I <= K; i++) {Dp[a[i].end]= Max (Dp[a[i].end], Dp[a[i].start-1] +A[I].W); for(intj = a[i].end +1; J <= v; ++j) Dp[j]= Max (Dp[j], dp[j-1]); } printf ("%d\n", Dp[v]); } return 0;}
"Dynamic planning" task scheduling