about running
#1041
-
I meet a strange problem, while running this data:
here is the code, see the line 56, if I delete this line, I will get And in VsCode, I can get output though I delete line 56. I don't know why, could you help me? // Problem: 木棒
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/169/
// Memory Limit: 64 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
using pii = pair<int, int>;
using ll = long long;
inline void read(int &x){
int s=0; x=1;
char ch=getchar();
while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=55;
int n, w[N];
int sum;
int m;
int g[N];
bool dfs(int u, int cnt, int need){
if(u==n+1){
if(cnt<m) return false;
return true;
}
bool ok=0;
rep(i,1,cnt) if(w[u]+g[i]<=need){
ok=1;
g[i]+=w[u];
if(dfs(u+1, cnt, need)) return true;
g[i]-=w[u];
}
if(cnt<m){
ok=1;
g[cnt+1]=w[u];
if(dfs(u+1, cnt+1, need)) return true;
g[cnt+1]=0;
}
// cerr<<endl;
if(!ok) return false;
}
int main(){
while(cin>>n, n){
int mx=0;
sum=0;
rep(i,1,n) read(w[i]), sum+=w[i], mx=max(mx, w[i]);
sort(w+1, w+1+n, greater<int>());
int res=1e9;
for(int i=1; i<=sum/i; i++){
if(sum%i==0){
m=sum/i;
if(m<=n && mx<=i){
memset(g, 0, sizeof g);
if(dfs(1, 0, i)){
res=min(res, i);
}
}
m=i;
if(m<=n && mx<=sum/i){
memset(g, 0, sizeof g);
if(dfs(1, 0, sum/i)){
res=min(res, sum/i);
}
}
}
}
cout<<res<<endl;
}
return 0;
} |
Beta Was this translation helpful? Give feedback.
Answered by
ouuan
Jan 15, 2022
Replies: 1 comment 4 replies
-
There's no return statement after line 57, which results in undefined behavior. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
YuiQwert
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's no return statement after line 57, which results in undefined behavior.