Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
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;
}
📦 Looking for Codeforces Round 381 Div Problem Gosha? Check the best deals on Amazon.
🛒 Shop Codeforces Round 381 Div Problem Gosha on Amazon
As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.
Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
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;
}
📦 Looking for Codeforces Round 381 Div Problem Gosha? Check the best deals on Amazon.
🛒 Shop Codeforces Round 381 Div Problem Gosha on Amazon
As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.