ti
深搜(有点类似板子)
//深搜回溯求最大和
//直接贪心取值无法ac,浮点数没法dp
//把money都乘以100,小数点后两位映射到整数,就可以背包
#include<bits/stdc++.h>using namespace std;#define db doubleint n, m;
db sum;
priority_queue<db>heap;
db ans;void dfs(db res, db num) { //当前积累的报销值 第几个 深度if (res > num) return ;ans = max(ans, res);if(heap.empty()) return ;db iu = heap.top();heap.pop();dfs(res, num); //不用这张支票dfs(res + iu, num); //用这张支票heap.push(iu); //恢复状态
}int main() {while (cin >> sum >> n) {if (!n) break;while(heap.size()) heap.pop();for (int i = 0; i < n; i ++ ) {bool f = 1;char c1, c2;db d = 0, t;cin >> m;for (int j = 0; j < m; j ++ ) {cin >> c1 >> c2 >> t;if((c1 == 'A' || c1 == 'B' || c1 == 'C') && t <= 600){d += t;}else f = 0;}if (d > 1000 || !f || d > sum) continue;//cout<<"d:"<<d<<endl;heap.push(d);}ans = 0;dfs(0.0, sum);printf("%.2f\n", ans);}return 0;
}