社区讨论
WHAT THE ASS?
P2530[SHOI2001] 化工厂装箱员参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mi6o2409
- 此快照首次捕获于
- 2025/11/20 08:01 4 个月前
- 此快照最后确认于
- 2025/11/20 08:01 4 个月前
写记搜,WA
照题解改,RE
照AC代码改,RE
复制AC代码去掉注释和没用的数组,还是RE
在上一份代码基础上加了一个没用到的char数组,AC
在第一份WA50分代码上加一句
CPPchar way[101][11][11][11];
(这个数组程序里一次没用到)
变成AC
谁来给我解释一下这里到底发生了什么?!??!
50分代码:
CPP#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1024;
int n,a[N],c[4];
int f[101][11][11][11];
char s[8];
int dfs(int x){
if(f[x][c[1]][c[2]][c[3]])return f[x][c[1]][c[2]][c[3]];
if(!c[1]&&!c[2]&&!c[3])return 0;
int re=inf;
for(int i=1;i<=3;i++){
if(c[i]){
int t1=c[1],t2=c[2],t3=c[3],sb=c[i];
c[i]=0;
int j;
for(j=x;j<=x+sb-1&&j<=n;j++){
c[a[j]]++;
}
re=min(re,dfs(j));
c[1]=t1,c[2]=t2,c[3]=t3;
}
}
re++;
f[x][c[1]][c[2]][c[3]]=re;
return re;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%s",s);
switch(s[0]){
case 'A':a[i]=1;break;
case 'B':a[i]=2;break;
case 'C':a[i]=3;break;
}
}
int x;
for(x=1;x<=n&&x<=10;x++)c[a[x]]++;
printf("%d",dfs(x));
return 0;
}
AC代码:
CPP#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1024;
int n,a[N],c[4];
int f[101][11][11][11];
char way[101][11][11][11];
char s[8];
int dfs(int x){
if(f[x][c[1]][c[2]][c[3]])return f[x][c[1]][c[2]][c[3]];
if(!c[1]&&!c[2]&&!c[3])return 0;
int re=inf;
for(int i=1;i<=3;i++){
if(c[i]){
int t1=c[1],t2=c[2],t3=c[3],sb=c[i];
c[i]=0;
int j;
for(j=x;j<=x+sb-1&&j<=n;j++){
c[a[j]]++;
}
re=min(re,dfs(j));
c[1]=t1,c[2]=t2,c[3]=t3;
}
}
re++;
f[x][c[1]][c[2]][c[3]]=re;
return re;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%s",s);
switch(s[0]){
case 'A':a[i]=1;break;
case 'B':a[i]=2;break;
case 'C':a[i]=3;break;
}
}
int x;
for(x=1;x<=n&&x<=10;x++)c[a[x]]++;
printf("%d",dfs(x));
return 0;
}
WHAT THE ASS?
回复
共 2 条回复,欢迎继续交流。
正在加载回复...