Created
December 12, 2013 16:27
-
-
Save taikoubou/7930810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
typedef long long ll; | |
ll C,S,T,N; | |
ll solve(ll,ll,ll ,ll); | |
ll work[2][101]; | |
short int dp[5000][100001]; | |
int main(){ | |
int p = 0; | |
cin >> C >> S >> T; | |
cin >> N; | |
for(ll i=0;i<5000;i++)for(long j=0;j<100001;j++)dp[i][j] = -1; | |
for(int i=0;i<N;i++){ | |
cin >> work[0][i] >> work[1][i]; | |
} | |
cout << solve(0,S,C,0) << endl; | |
return 0; | |
} | |
ll solve(ll month,ll i_s,ll i_c,ll i_n){ | |
if(dp[month][i_s] != -1)return dp[month][i_s]; | |
if(i_s >= T){ | |
return dp[month][i_s] = month; | |
} | |
else{ | |
ll res=-1,rec,t = i_s+i_c,tm = i_s+i_c+work[1][i_n]-work[0][i_n]; | |
if(i_s >= work[0][i_n] && i_n < N)res = solve(month+1,tm,work[1][i_n]+i_c,i_n+1); | |
rec = solve(month+1,t,i_c,i_n); | |
if(res != -1){ | |
if(rec < res)t = tm; | |
rec = min(res,rec); | |
} | |
return dp[rec][t] = rec; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment