zoukankan      html  css  js  c++  java
  • P2089 烤鸡

    https://www.luogu.com.cn/problem/P2089

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n, cnt=0, ans[60000][10];
     4 //最多情况是3^10= 59049,所以开60000二维数组,用二维数组存储结果 :第一维表示方案数,第二维存储该方案结果 
     5 int main()
     6 {
     7     
     8     cin>>n;
     9     if(n<10 || n>30)//去除0的情况 
    10         cout<<0;
    11     else
    12     {
    13         for(int a=1; a<=3; a++)
    14             for(int b=1; b<=3; b++)
    15                 for(int c=1; c<=3; c++)
    16                     for(int d=1; d<=3; d++)
    17                         for(int e=1; e<=3; e++)
    18                             for(int f=1; f<=3; f++)
    19                                 for(int g=1; g<=3; g++)
    20                                     for(int h=1; h<=3; h++)
    21                                         for(int i=1; i<=3; i++)
    22                                             for(int j=1; j<=3; j++)
    23                                                     if(a+b+c+d+e+f+g+h+i+j==n)//判断是否符合答案,并存储 
    24                                                     {
    25                                                         cnt++;
    26                                                         ans[cnt][0]=a; ans[cnt][1]=b;
    27                                                         ans[cnt][2]=c; ans[cnt][3]=d;
    28                                                         ans[cnt][4]=e; ans[cnt][5]=f;
    29                                                         ans[cnt][6]=g; ans[cnt][7]=h;
    30                                                         ans[cnt][8]=i; ans[cnt][9]=j;
    31                                                     }
    32         cout<<cnt<<endl;//输出方案数和答案 
    33         for(int i=1; i<=cnt; i++)
    34         {
    35             for(int j=0; j<10; j++)
    36                 cout<<ans[i][j]<<" ";
    37             cout<<endl;
    38         }
    39     }
    40     
    41     return 0;
    42 }
  • 相关阅读:
    poj 3378 Crazy Thairs 夜
    1487. Chinese Football 夜
    容斥原理
    Dancing Links
    三角剖分
    模线性方程模板
    模线性方程
    容斥原理 POJ2773
    DNA Sequence [矩阵]
    hdu 2588 容斥
  • 原文地址:https://www.cnblogs.com/tflsnoi/p/13299079.html
Copyright © 2011-2022 走看看