HDU 2510 symbol triangle dfs+ Play table

Source: Internet
Author: User
Tags cmath

Test instructions

The 1th line of the symbol triangle has n a symbol consisting of "+" and "-", each line is 1 less than the upstream, 2 are "+" under the same number, and 2 are "-" under the different number. Calculates how many different symbol triangles have the same number of "+" and "-".

Exercises

We will + think that 1,-is 0. Then the operation in the test instructions becomes an XOR operation.

We draw from a symbol to a plurality of symbolic derivations, and we find that for the new row, as long as the first symbol is determined, then the symbol after the line is determined (because the next symbol is the symbol of the previous layer and the left symbol). So we only need to enumerate the first symbol each time we add the line, then the number of statistics 1 and the total number of comparisons can be judged whether the conditions are met. We use Dfs to derive. This approach takes a long time (more than 6S), so it cannot be used directly, but can be used to find the results of each value.

Since the result is static, we can get the result directly with DFS and then hit the table output.




Code:

#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm

> #include <iostream> #include <vector> #include <map> using namespace std;
const int maxn=30;
int ans[maxn]={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 main () {int n;
        while (scanf ("%d", &n)!=eof) {if (n==0) break;
    printf ("%d%d\n", n,ans[n-1]);
} return 0;
}/*/Normal DFS, time consuming more than 6S. #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm

> #include <iostream> #include <vector> #include <map> using namespace std;
const int maxn=30;
int F[MAXN][MAXN];
int RES[MAXN];
    void Dfs (int t,int s) {int i,j,ans;
        for (i=0;i<2;i++) {f[t][0]=i;
        Ans=i;
            for (j=1;j<t;j++) {f[t][j]=f[t][j-1]^f[t-1][j-1];
        ANS+=F[T][J];
        }if ((1+t) *t/2== (ans+s) * *) res[t]++;
        if (t==24) continue;
    DFS (T+1,s+ans);
    }} void Init () {memset (f,0,sizeof (f));
    memset (res,0,sizeof (res));
DFS (1,0);
    } int main () {init ();
        for (int i=1;i<=24;i++) {if (i==1) printf ("{%d", res[i]);
        else if (i==24) printf (",%d}\n", Res[i]);
    else printf (",%d", res[i]);
 }
}
*/


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.