Use dp[i][j] to indicate the first I task, a complete need J time, B completed need dp[i][j] time.
The recursive equation is also easy to get out
Dp[i][j]=min (Dp[i-1][j]+b[i],dp[i-1][j-a[i])//Where A[i],b[i] respectively indicates the time required for A/b to complete the task I.
Attached code
1#include <algorithm>2#include <iostream>3#include <fstream>4#include <cstdlib>5#include <cstring>6#include <cmath>7 using namespacestd;8Ifstream Fin ("divide.in");9Ofstream Fout ("Divide.out");Ten intdp[203][40005]={0},rws=0, rw[203][2]={0}; One intMainvoid) A { -Fin>>RWS; - for(intI=1; i<=rws;i++) fin>>rw[i][0]>>rw[i][1]; thedp[0][0]=0; - intnum=0; - for(intI=1; i<=rws;i++) - { +num+=rw[i][0]; - for(intj=0; j<=num;j++) + { Adp[i][j]=dp[i-1][j]+rw[i][1]; at if(j>=rw[i][0]) - { -Dp[i][j]=min (dp[i][j],dp[i-1][j-rw[i][0]]); - } - } - } in intans=0x7fffffff; - for(intI=1; i<=num;i++) to { +ans=min (Ans,max (dp[rws][i],i)); - } thefout<<ans; * return 0; $}
"Solving" task assignments