# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210586 | mayhoubsaleh | Visiting Singapore (NOI20_visitingsingapore) | C++14 | 222 ms | 45688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <string>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=5050;
int n,k,m,a,b;
int s[maxn],t[maxn],val[maxn];
int dp[maxn][maxn][2];
bool vis[maxn][maxn][2];
int solve(int i,int j,int took,int happy=0){
//cout<<i<<' '<<j<<' '<<took<<' '<<happy<<endl;
if(vis[i][j][took])return dp[i][j][took];
vis[i][j][took]=1;
int &ans=dp[i][j][took];
if(i==n&&j==m)return ans=happy;
if(i==n)return ans=solve(i,j+1,0,happy+b+(a*took));
if(j==m)return ans=solve(i+1,j,took,happy);
ans=solve(i,j+1,0,happy+b+(a*took));
//return ans;
if(s[i]==t[j]){
ans=max(ans,solve(i+1,j+1,1,happy+val[s[i]]));
}
ans=max(ans,solve(i+1,j,took,happy));
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |