题意:
每个任务有所需时间、DDL、价值。最大化总价值
任务数 <= 100,所需时间 <=20,DDL <= 2000,价值 <= 20
思路:
按DDL从小到大排序,然后做一个正常的01背包
或许跟 gym103640 M. Most Ordered Way 有一点点相似?单线程做任务,都是先做ddl靠前的
const signed N = 103, M = 2003; int n, f[N][M], pre[N][M]; struct node { int t, d, p, id; void rd(int i) { cin >> t >> d >> p, id = i; } } a[N]; vector<int> ve; void dfs(int n, int m) { //回溯路径 if(!n) return; int pm = pre[n][m]; dfs(n-1, pm); if(f[n][m] > f[n-1][pm]) ve.pb(a[n].id); } signed main() { iofast; cin >> n; for(int i = 1; i <= n; i++) a[i].rd(i); sort(a + 1, a + 1 + n, [](const node &a, const node &b) { return a.d < b.d; }); memset(f, -1, sizeof f); f[0][0] = 0; for(int i = 1; i <= n; i++) for(int j = 0; j < a[i].d; j++) { if(~f[i-1][j]) f[i][j] = f[i-1][j], pre[i][j] = j; if(j >= a[i].t && f[i-1][j-a[i].t] + a[i].p > f[i][j]) if(~f[i-1][j-a[i].t]) //要来自合法的状态 f[i][j] = f[i-1][j-a[i].t] + a[i].p, pre[i][j] = j-a[i].t; } int p = max_element(f[n], f[n]+M) - f[n]; cout << f[n][p] << endl; dfs(n, p); cout << ve.size() << endl; for(int i : ve) cout << i << ' '; }