Codeforces Round #381 (Div. 1), problem: (E) Gosha is hunting Solution in C/C++

Hi guys , I just solved the fifth problem of round 381 , Hope you like it , feel free to comment any better solution .

 

 

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2007;
pair<double,double> p[MAXN];
double dp[MAXN][MAXN];
int main(){
int n,x,y;;
cin>>n>>x>>y;
for (int i=0;i<n;i++){
cin>>p[i].first;
}
for (int i=0;i<n;i++){
cin>>p[i].second;
}
for (int k=0;k<n;k++){
double s=1-(1-p[k].first)*(1-p[k].second);
for (int i=min(x,k);i>=max(0,x-n+k);i–){
for (int j=min(y,k);j>=max(0,y-n+k);j–){
dp[i+1][j]=max(dp[i+1][j],dp[i][j]+p[k].first);
dp[i][j+1]=max(dp[i][j+1],dp[i][j]+p[k].second);
dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+s);
}
}
}
cout<<dp[x][y]<<endl;
return 0;
}

(Visited 72 times, 1 visits today)

About the Author:

Leave A Comment