If you multiply each number by 100, you can solve the problem.
Continue to post code (your code is ugly ~~~)
<Span style = "font-size: 18px; "> # include <iostream> # include <algorithm> # include <cstring> # include <cstdio> # define maxn 3100000 using namespace STD; int DP [maxn]; int P [31]; int main () {double Q; int N, V; while (~ Scanf ("% lf % d", & Q, & N) {int K = 0; V = Q * 100; while (n --) {int m, flag = 1; double Ts = 0, A; char s [10]; CIN> m; double va, VB, VC; VA = VB = VC = 0; while (M --) {CIN> S; If (s [0]! = 'A' & S [0]! = 'B' & S [0]! = 'C') {flag = 0;} else {sscanf (S, "% * [A-Z]: % lf", & ); // I used the sscanf function. You can input scanf ("% C: % lf", & Ch, & A) like this ); if (s [0] = 'A') {va + = A; If (va> 600) Flag = 0 ;} if (s [0] = 'B') {VB + = A; If (VB> 600) Flag = 0 ;} if (s [0] = 'C') {VC ++ = A; If (VC> 600) Flag = 0 ;}}} if (va + VB + VC> 1000) Flag = 0; If (FLAG) P [k ++] = (va + VB + Vc) * 100;} memset (DP, 0, sizeof DP); For (INT I = 0; I <K; I ++) {for (Int J = V; j> = P [I]; j --) {DP [J] = max (DP [J], DP [J-P [I] + P [I]); // copy the 01 equation} printf ("%. 2lf \ n ", 1.0 * DP [v]/100); // The output is converted to double type} return 0 ;}</span>