Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
51834 UhhhQQQU 最优子序列 C++ 解答错误 25 159 MS 208460 KB 952 2022-07-13 16:10:41

Tests(5/20):


#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N=3e3+10; typedef long long ll; ll f[N][(1<<13)+1]; int pre[N][(1<<13)+1]; int n,k,type; char ch[N]; int lst[N][14]; int main() { scanf("%d %d %d",&n,&k,&type); scanf("%s",ch+1); for(int i=1;i<=n+1;i++) { for(int j=0;j<k;j++) lst[i][j]=lst[i-1][j]; lst[i][ch[i-1]-'a']=i-1; } f[n+1][1<<(ch[n]-'a')]=1; for(int i=n+1;i>=1;i--) { for(int s=0;s<(1<<k);s++) { if(!f[i][s]) continue; for(int j=0;j<k;j++) { if(!lst[i][j]) continue; if(ch[lst[i][j]]==ch[i]) f[lst[i][j]][s]=max(f[lst[i][j]][s],f[i][s]+1); else if((s&(1<<j))==0) f[lst[i][j]][s|(1<<(ch[lst[i][j]]-'a'))]=max(f[lst[i][j]][s|(1<<(ch[lst[i][j]]-'a'))],f[i][s]+1); } } } ll ans=0; for(int i=n+1;i>=1;i--) for(int s=0;s<(1<<k);s++) ans=max(ans,f[i][s]); printf("%lld\n",ans); return 0; }


测评信息: