输入24,你的方案数已经大于1000了,
1000的二维数组肯定不够,你开大一点应该就可以了。
by IamZZ @ 2024-03-16 11:44:01
~~快忘了咋做了~~
```cpp
#include<iostream>
using namespace std;
int main(){
int n,cnt=0;
cin>>n;
if(n>30){
cout<<0;
return 0;
}
for(int a=1;a<=3;a++){
for(int b=1;b<=3;b++){
for(int c=1;c<=3;c++){
for(int d=1;d<=3;d++){
for(int e=1;e<=3;e++){
for(int f=1;f<=3;f++){
for(int g=1;g<=3;g++){
for(int h=1;h<=3;h++){
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
if(a+b+c+d+e+f+g+h+i+j==n){
cnt++;
}
}
}
}
}
}
}
}
}
}
}
cout<<cnt<<endl;
for(int a=1;a<=3;a++){
for(int b=1;b<=3;b++){
for(int c=1;c<=3;c++){
for(int d=1;d<=3;d++){
for(int e=1;e<=3;e++){
for(int f=1;f<=3;f++){
for(int g=1;g<=3;g++){
for(int h=1;h<=3;h++){
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
if(a+b+c+d+e+f+g+h+i+j == n) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g<<" "<<h<<" "<<i<<" "<<j<<" "<<endl;
}
}
}
}
}
}
}
}
}
}
return 0;
}
```
by dzsf_lhz @ 2024-03-16 11:45:22
解决了!感谢大佬!!
by spessert @ 2024-03-20 21:59:17
@[dzsf_lhz](/user/946954) 感谢!!
by spessert @ 2024-03-20 21:59:53
@[IamZZ](/user/552509) 感谢大佬!!!
by spessert @ 2024-03-20 22:00:16