【SWUST OJ】 698: Independent Task Scheduling
Independent Task Scheduling
首先给予dp数组定义
dp[i][j] 为前i个工作,A工作时间为j时,B的工作时间
然后这题就变成水题了
首先状态转移方程为
dp[i][j] = min(dp[i-1][j-a[i]],dp[i-1][j] + b[i]);
然后枚举每一个A所需要的时间直到A机器所有作业时间总和
取得max(i,dp[n][i]) 为做完所有作业需要的时间, 然后取最小值即为所求
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <string> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <bitset> #include <algorithm> #include <climits> #include<cstring> using namespace std; #define Pair pair<int, int> #define ULL unsigned long long #define LS l,mid,lson #define RS mid+1,r,rson #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) #define girlfriend zy #define ll long long const int maxn = 100000; using namespace std; int a[maxn]; int b[maxn]; int dp[maxn][1000]; int main() { int n; cin>>n; int sum = 0; int ans = INF; for(int i=1;i<=n;i++) { cin>>a[i]; sum+=a[i]; } for(int i=1;i<=n;i++) { cin>>b[i]; } for(int i=1;i<=n;i++) { for(int j=0;j<=sum;j++) { if(a[i] <= j) { dp[i][j] = min(dp[i-1][j-a[i]],dp[i-1][j] + b[i]); } else { dp[i][j] = dp[i-1][j] + b[i]; } } } for(int i=1;i<=sum;i++) { int t; t = max(i,dp[n][i]); ans = min(t,ans); } cout<<ans<<endl; }