Luo Gu P2727 01 string Stringsobits

P2727 01串 Stringsobits

Read the solution to a problem before doing (copy) out, dp good weak ah

DP [i] [j] denotes the front i j-th bit string of numbers 1.

Transfer equation DP [I] [J] DP = [. 1-I] [J-. 1] + DP [. 1-I] [J] .

How to find the serial number of the focus of it

For us k (0-> l) A traversal and prefixes. When found to be for the prefix and sum [i]> = p && sum [i-1] , then there must be the i-th bit is 1, (it should be easy to occur)

More difficult is the next request next, because this is a current, so the current position is to have some statistics to zero. We only need to consider the current bit is 1, the back of the n-1 bits, l-1 one can bring a p-sum [i-1] strings.

Recursive statistics on it. Note boundary, k 0 from the start.

PS : I am talking about feeling very unclear: (

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn=32+5;
 5 int n,m;
 6 ll a[maxn];
 7 ll s[maxn];
 8 ll dp[maxn][maxn];
 9 int num[32];
10 
11 void solve(ll n,ll l,ll m)
12 {
13     ll s=0,last;
14     for(int i=0;i<=n;i++)
15     {
16         last=s;
17         s=0;
18         for(int j=0;j<=l;j++)
19         {
20             s+=dp[i][j];
21             if(s>=m)
22             {
23                 num[i]=1;
24                 solve(n-1,l-1,m-last);
25                 return;
26             } 
 27          }
 28      }
 29  }
 30  int main ()
 31 is  {
 32      STD :: :: iOS sync_with_stdio ( to false );
 33 is      LL n-, L, m; CIN L >> >> >> n- m;
 34 is      // before i type bit digit number j 1 
 35      // DP [1] [0] = 1;
 36      // DP [1] [1] = 2; 
37 [      for ( int I = 0 ; I <= n-; I ++) DP [I] [ 0 ] = . 1 ;
 38 is      for ( int I = . 1 ; <= n-I; I ++ )
39     {
40         for(int j=1;j<=i;j++)
41         {
42             dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
43         }
44     }
45     //cout <<dp[1][1]<<endl;
46     
47     solve(n,l,m);
48     for(int i=n;i>=1;i--)
49         if(num[i]) cout <<1;
50             else cout <<0;
51     cout <<endl;
52     return 0;
53 } 

 

Guess you like

Origin www.cnblogs.com/Msmw/p/11330640.html