C. George and Job
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.
JUST FIX STARTING POINTS IF WE ARE CONSIDERING A POINT AS A NEW STARTING POINT THAN GO TO M INDEX FORWARD , ELSE SHIFT TO NEXT INDEX ....
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli dp[5010][5010];
lli n,m,k;
lli arr[100000];
lli fs[100000];
lli solve(int start,int cov)
{
if(dp[start][cov]!=-1) return dp[start][cov];
else if(cov==k) return 0;
else if(start>n)
{
return INT_MIN;
}
else
{
// cout<<start<<endl;
lli ret=0;
if(start+m-1<=n)
{
ret=solve(start+m,cov+1)+fs[start+m-1]-fs[start-1];
}
ret=max(ret,solve(start+1,cov));
dp[start][cov]=ret;
return ret;
}
}
int main()
{
cin>>n>>m>>k;
memset(dp,-1,sizeof dp);
for(int i=1;i<=n;i++)
{
cin>>arr[i];
fs[i]=fs[i-1]+arr[i];
// cout<<fs[i]<<endl;
}
lli ans=solve(1,0);
cout<<ans<<endl;
}
No comments:
Post a Comment