QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#216018 | #7562. Except One | solemntee | WA | 1ms | 4092kb | C++17 | 1.2kb | 2023-10-15 15:12:24 | 2023-10-15 15:12:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
scanf("%d",&n);
vector<int>a(n+2);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
//for(int i=1;i<=n;i++)a[i]+=500;
vector<vector<vector<int>>>dp(n+1,vector<vector<int>>(n+1,vector<int>(n+2,-1)));
a[n+1]=1e9+50;
function<int(int,int,int)>dfs=[&](int l,int r,int val){
if(dp[l][r][val]!=-1)return dp[l][r][val];
if(l==r){
if(a[l]==a[val])return dp[l][r][val]=0;
return dp[l][r][val]=1;
}
dp[l][r][val]=r-l+1;
for(int i=l;i<r;i++){
for(int j=0;j<=n+1;j++){
for(int k=0;k<=n+1;k++){
dp[l][r][val]=min(dp[l][r][val],dfs(l,i,j)+dfs(i+1,r,k)+(a[j]!=a[val])+(a[k]!=a[val]));
}
}
for(int j=0;j<=n+1;j++){
dp[l][r][val]=min(dp[l][r][val],dfs(l,i,j)+dfs(i+1,r,j)+(a[j]!=a[val]));
}
}
return dp[l][r][val];
};
printf("%d",dfs(1,n,0));
}
/*
6
1 1 4 5 1 4
5
1 2 3 2 1
23
11 11 26 26 26 26 26 26 26 45 45 15 15 15 15 0 96 41 41 41 96 96 0
*/
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4092kb
input:
7 5 3
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'