【dp】VK Cup 2012 Qualification Round 1 ——E

E dp

类似01背包,只是这里不一定取完k个,而01背包则一定取完k个

int dp[4444];
int ans;
int main(){
    int n,m;
    cin>>n>>m;
    int i,j;
    int s,d;
    ans = 0;
    while(n--){
        cin>>s>>d;
        for(i=m;i>=0;i--){
            if(s<=dp[i])dp[i] += d;
            else {
                ans = max(ans,s-dp[i]-1);
                dp[i] = s+d-1;
            }
            if(i>0)
            dp[i] = min(dp[i],dp[i-1]);
        }
    }
    for(i=0;i<=m;i++)ans = max(ans,86400-dp[i]);
    cout<<ans<<endl;
    return 0;
}




















你可能感兴趣的:(【dp】VK Cup 2012 Qualification Round 1 ——E)