http://acm.hdu.edu.cn/showproblem.php?pid=1864
The maximum reimbursement
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 36208 Accepted Submission(s): 11135
Problem Description
Existing sum of money can be reimbursed a certain amount of the invoice. Invoice types include reimbursement allowed to buy the book (A type), stationery (Class B), the total travel (C Type), requires each invoice shall not exceed 1000, every invoice, not the value of the individual items of over $ 600 . Now you write a program to find a pile of invoices for reimbursement given, not to exceed the maximum reimbursement quotas degrees.
Input
Test input contains several test cases. Each row of the first test comprises two positive numbers Q and N, wherein Q is given reimbursement, N (<= 30) is the number of invoices. Followed by N-line input, the format of each line is:
m type_1: PRICE_1 TYPE_2: price_2 ... Type_m: price_m
wherein m is a positive integer number of articles on the member opened by the invoice, Type_i item type and i are price_i article and value. Categories of items represented by a capital letters. When N is 0, all the input end, an output not corresponding results.
m type_1: PRICE_1 TYPE_2: price_2 ... Type_m: price_m
wherein m is a positive integer number of articles on the member opened by the invoice, Type_i item type and i are price_i article and value. Categories of items represented by a capital letters. When N is 0, all the input end, an output not corresponding results.
Output
An output line for each test case, i.e., the maximum amount may be reimbursed, 2 decimal place.
Sample Input
200.00 3 2 A:23.50 B:100.00 1 C:650.00 3 A:59.99 A:120.00 X:10.00 1200.00 2 2 B:600.00 A:400.00 1 C:200.50 1200.50 3 2 B:600.00 A:400.00 1 C:200.50 1 A:100.00 100.00 0
Sample Output
123.50 1000.00 1200.50
Source
Recommend
//#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdio.h> #include <queue> #include <stack> #include <map> #include <set> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define mod 1000000007 #define PI acos(-1) using namespace std; typedef long long ll ; int dp[3000009] , w[30]; int main() { double n ; double v ; while(~scanf("%lf%lf" , &v , &n) && n) { int flag ; memset(w , 0 , sizeof(w)); memset(dp , 0 , sizeof(dp)); for(int i = 1 ; i <= n ; i++) { int num ; scanf("%d" , &num); flag = 1 ; int x , y , z ; x = y = z = 0 ; for(int j = 1 ; j <= num ; j++) { double val ; char c , d; cin >> c >> d >> val ; val = val * 100 ; if(c == 'A' && x + val <= 60000) { x += val ; } else if(c == 'B' && y + val <= 60000) { y += val ; } else if(c == 'C' && z + val <= 60000) { z += val ; } else { flag = 0 ; } } if(x + y + z <= 100000 && flag) w[i] = x + y + z ; } int vv = v * 100 ; for(int i = 1 ; i <= n ; i++) { for(int j = vv ; j >= w[i] ; j--) { dp[j] = max(dp[j] , dp[j-w[i]]+w[i]); } } printf("%.2lf\n" , (double)dp[vv]/100); } return 0; }