P2089 烤鸡

P2089 烤鸡

题目链接:https://www.luogu.org/problem/P2089

思路:

​ 很简单,就是不停for循环;

代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,a,b,c,d,e,f,g,h,i,j,m=0;
    cin>>n;
    for(a=1;a<=3;a++){
        for(b=1;b<=3;b++){
            for(c=1;c<=3;c++){
                for(d=1;d<=3;d++){
                    for(e=1;e<=3;e++){
                        for(f=1;f<=3;f++){
                            for(g=1;g<=3;g++){
                                for(h=1;h<=3;h++){
                                    for(i=1;i<=3;i++){
                                        for(j=1;j<=3;j++){
                                            if(a+b+c+d+e+f+g+h+i+j==n){
                                                m++;
                                            }
                                        }
                                    }
                                }
                             }
                        }
                    }
                }
            }
        }
    }
    if(m==0){
        cout<<"0"<<endl;
    }else{
        cout<<m<<endl;
    for(a=1;a<4;a++){
        for(b=1;b<4;b++){
            for(c=1;c<4;c++){
                for(d=1;d<4;d++){
                    for(e=1;e<4;e++){
                        for(f=1;f<4;f++){
                            for(g=1;g<4;g++){
                                for(h=1;h<4;h++){
                                    for(i=1;i<4;i++){
                                        for(j=1;j<4;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;
}
posted @ 2019-07-27 15:53  幽灵小一只  阅读(278)  评论(0编辑  收藏  举报