Блог пользователя toilanvd_HUST

Автор toilanvd_HUST, 12 лет назад, По-английски

Can anyone solve this problem not using brute force? I'm so happy if somebody can help me.

A beautiful bit string is a string which can be described as a right bracket string, and lexicography order not larger than all of its bracket-circle-permutation. For example: 111000 -> ((())) is a beautiful string (110001 -> (()))( is not a right permutation), but 101 -> ()( is not, and 110010 is also not, because 110010 > 101100 and 101100 -> ()(()) is a bracket-circle-permutation of 110010.

(I have changed the problem set, this is my original problem, I realize that the last one I wrote is not enough to solve my original one.)

Count the number of beautiful strings with n bit. And let a n-bit beautiful string, count the number of beautiful strings which have lexicography order smaller than this. Of course, n is even.

  • Проголосовать: нравится
  • +16
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится -16 Проголосовать: не нравится

Looks like it's some kind of dp problem.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

Looks like the number of beautiful strings with n bit is equal to the number of binary necklaces of length n. link
Sorry for my bad English.

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Thank you! My original problem is harder than this one. A beautiful bit string is a string which can be described as a right bracket string, and lexicography order not larger than all of its bracket-circle-permutation. For example: 111000 -> ((())) is a beautiful string, but 101 -> ()( is not. Of course, n is even. I still find it so hard to solve.

    • »
      »
      »
      12 лет назад, скрыть # ^ |
      ← Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      "A beautiful bit string is a string which can be described as a right bracket string"

      You didn't tell us about this in your above statement. Please update your post to prevent misunderstanding.

      Solution of NuM didn't resolved the second requirement of the statement, it is much harder than the first.

    • »
      »
      »
      12 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +5 Проголосовать: не нравится

      My solution for your original problem: Complexity: O(n^4)

      #include <stdio.h>
      #include <iostream>
      #include <algorithm>
      using namespace std;
      
      #define long long long
      #define f1(i,n) for (int i=1; i<=n; i++)
      #define f0(i,n) for (int i=0; i<n; i++)
      
      #define N 102
      bool GG[N][N]; long G[N][N];
      bool FF[N][N][N][2]; long F[N][N][N][2];
      
      long g(int n, int Level) {
      	if (n<=0 || Level<=0) return n==0 && Level==0;
      	if (GG[n][Level]++) return G[n][Level];
      	return G[n][Level] = g(n-1, Level+1) + g(n-1, Level-1);
      }
      
      #define C n][k][Level][ForceDown
      long f(int n, int k, int Level, bool ForceDown){
      	if (Level<=0 || n<=0) return Level==0 && n==0;
      	if (FF[C]++) return F[C];
      	long Sum = f(n-k, k, Level-1, false);
      	if (!ForceDown) Sum += f(n-k, k, Level+1, 0);
      	if (k!=1) for (int i=1; i<=n-1; i++)
      	Sum += f(n-i, k-1, Level, true) * g(i-1, Level+1);
      	return F[C]=Sum;
      }
      
      main(){
      	long Sum=0; int n;
      	scanf("%d", &n);
      	f1(i,n) Sum += f(n-i, i, 1, false);
      	cout << Sum << endl;
      }
      
      
      
    • »
      »
      »
      12 лет назад, скрыть # ^ |
      ← Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      This problem is equivalent to counting the number of necklaces of length n with the same number of white and black beads. So it can be solved using similar techniques.
      upd: number of such necklaces of length 2*n is equal to