社区讨论
萌新求助区间dp (70pts WA)
P4170[CQOI2007] 涂色参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lo7mu9at
- 此快照首次捕获于
- 2023/10/27 04:24 2 年前
- 此快照最后确认于
- 2023/10/27 04:24 2 年前
为什么这样子是错的呀 qwq
(WA on #3,#4,#10 | 70pts)
思路是把输入数据中连续相同字符进行合并,这样就不会出现相邻相同的情况。然后在 时 理应 可以用 来更新 ,但为什么挂了呢 qwq
把 时的转移式改成 就过了
CPP#include<bits/stdc++.h>
#define ll long long
#define For(i,l,r) for(int i=l;i<=r;++i)
using namespace std;
const int N=55,Inf=0x7fffffff,Mod=998244353;
char cch;
int res,zf;
inline int rd()
{
while((cch=getchar())<45);
if(cch^45)res=cch^48,zf=1;
else res=0,zf=-1;
while((cch=getchar())>=48)res=(res*10)+(cch^48);
return res*zf;
}
inline void print(int x)
{
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n,len;
char a[N],b[N];
int f[N][N];
int main()
{
//freopen("P4170.in","r",stdin);
//freopen("P4170.out","w",stdout);
memset(f,63,sizeof(f));
scanf("%s",b+1);
len=strlen(b+1);
For(i,1,len) if(b[i]^b[i-1]) a[++n]=b[i],f[n][n]=1;
For(len,2,n)
{
For(l,1,n-len+1)
{
int r=l+len-1;
if(a[l]==a[r]) f[l][r]=f[l+1][r-1]+1;
For(k,l,r-1) f[l][r]=min(f[l][r],f[l][k]+f[k+1][r]);
}
}
cout<<f[1][n];
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...