zoukankan      html  css  js  c++  java
  • hdu2510 爆搜+打表

    符号三角形

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1899    Accepted Submission(s): 977


    Problem Description
    符号三角形的 第1行有n个由“+”和”-“组成的符号 ,以后每行符号比上行少1个,2个同号下面是”+“,2个异 号下面是”-“ 。计算有多少个不同的符号三角形,使其所含”+“ 和”-“ 的个数相同 。 n=7时的1个符号三角形如下:
    + + - + - + +
    + - - - - +
    - + + + -
    - + + -
    - + -
    - -
    +
     
    Input
    每行1个正整数n <=24,n=0退出.
     
    Output
    n和符号三角形的个数.
     
    Sample Input
    15 16 19 20 0
     
    Sample Output
    15 1896 16 5160 19 32757 20 59984
    越来越感觉自己智障了= =
    破题第一次看每一点思路,后来disguss看打表还是不知道咋搜,
    今天突然意识到类似于一颗二叉树,用0,1分别代替+,-;则a,b二者的儿子就是a^b;
    直接开二维数组(mdzz先开始一直想着用一维数组鼓捣半天公式也没整出来),dfs出倒三角的第一行,在调函数补全这个三角,判断+-个数,满足就打表>_<
    代码太水不发了

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    using namespace std; //1表示-,0表示+
    long long num[25]={0,0,4,6,0,0,12,40,0,0,171,410,0,0,1896,5160,0,0,32757,59984,0,0,431095,822229};
    int a[30][30],n,counts;
    void pd();
    void dfs(int id)
    {
    if(id==n+1) {pd();return;}
    for(int i=0;i<=1;i++)
    a[1][id]=i,dfs(id+1);
    }
    void pd()
    {
    int i,j,k=1,sumn=n*(n+1)/4,temp,one=0,two=0,sumn2,q=n+1;
    int digit[2]={0,0};
    for(i=1;i<=n;i++) digit[a[1][i]]++;
    for(i=2;i<=n;i++){
    for(j=1;j<=n+1-i;j++){
    a[i][j]=(a[i-1][j]^a[i-1][j+1]);
    digit[a[i][j]]++;
    }
    //if(digit[0]>sumn||digit[1]>sumn) return;
    }
    if(digit[0]==digit[1]) counts++;
    }
    int main()
    {
    for(n=1;n<=24;n++) {if(n==15||n==16||n==19||n==20) continue;counts=0;dfs(1);cout<<counts<<",";}
    int m,i,j,k,n;
    return 0;
    }

     
  • 相关阅读:
    Atcoder Regular Contest 123 题解
    Atcoder Grand Contest 015 F Kenus the Ancient Greek(找性质+乱搞)
    Solution 「CF 575G」Run for beer
    Solution 「CF 510E」Fox And Dinner
    Solution 「洛谷 P4389」付公主的背包
    Solution 「CF 555E」Case of Computer Network
    Solution 「CF 802C」Heidi and Library (hard)
    Solution 「JOISC 2020」「UOJ #509」迷路的猫
    Div弹出框
    JS对话框
  • 原文地址:https://www.cnblogs.com/zzqc/p/6544805.html
Copyright © 2011-2022 走看看