# bzoj 4069 [Apio2015]巴厘岛的雕塑 dp

## [Apio2015]巴厘岛的雕塑

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 494  Solved: 238
[Submit][Status][Discuss]

## Description

P 与 Q 按位取或后的结果是： (pM−1  OR  qM−1)(pM−2 OR qM−2)…(p1 OR q1)(p0 OR q0)。其中：
0 OR 0=0
0 OR 1=1
1 OR 0=1
1 OR 1=1

6 1 3
8 1 2 1 5 4

11

explanation

## HINT

子任务 1 （9 分）

1< = N< = 20

1< = A< = B< = N

0< = Yi< = 1000000000

1< = N< = 50

1< = A< = B< = min{20,N}

0< = Yi< = 10

1< = N< = 100

A=1

1< = B< = N

0< = Yi< = 20

1< = N< = 100

1< = A< = B< = N

0< = Yi< = 1000000000

1< = N< = 2000

A=1

1< = B< = N

0< = Yi< = 1000000000

## 发现是or，然后无语了，这道题的话从高往低贪心是没问题的。

 1 #include<cstring>
2 #include<cmath>
3 #include<iostream>
4 #include<cstdio>
5 #include<algorithm>
6
7 #define N 107
8 #define ll long long
9 using namespace std;
11 {
12     int x=0,f=1;char ch=getchar();
13     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
14     while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
15     return x*f;
16 }
17
18 int n,A,B;
19 int g[N*20];
20 bool f[N][N];
21 ll ans,sum[N*20],a[N*20];
22
24 {
25     ll x=sum[n],wei=0;
26     while (x) wei++,x>>=1;ans=0,wei--;
27     for (;~wei;wei--)
28     {
29         ll res=(1ll<<wei)-1+ans;
30         memset(f,0,sizeof(f));f[0][0]=true;
31         for (int i=1;i<=n;i++)
32             for (int j=1;j<=min(i,B);j++)
33                 for (int k=j-1;k<=i-1;k++)
34                     f[i][j]|=f[k][j-1]&&((res|(sum[i]-sum[k]))==res);
35         bool boo=false;
36         for (int i=A;i<=B;i++)
37             boo|=f[n][i];
38         if (!boo) ans+=(1ll<<wei);
39     }
40     printf("%lld\n",ans);
41 }
43 {
44     ll x=sum[n],wei=0;
45     while (x) wei++,x>>=1;ans=0,wei--;
46     for (;~wei;wei--)
47     {
48         ll res=(1ll<<wei)-1+ans;
49         memset(g,0x7f,sizeof(g));g[0]=0;
50         for (int i=1;i<=n;i++)
51             for (int j=0;j<=i-1;j++)
52                 if ((res|(sum[i]-sum[j]))==res) g[i]=min(g[i],g[j]+1);
53         int boo=false;
54         if (g[n]<=B) boo=true;
55         if (!boo) ans+=(ll)(1ll<<wei);
56     }
57     printf("%lld\n",ans);
58 }
59 #undef ll
60 #undef N
61 int main()
62 {
63     freopen("fzy.in","r",stdin);
64     freopen("fzy.out","w",stdout);
65
70 }