Codeforces 981 D.Bookshelves(数位DP)

[Codeforces 981 D.Bookshelves](http://codeforces.com/problemset/problem/981/D) 题目大意: 给n个数,将这n个数分为k段,(n,k<=50)分别对每一段求和,再将每个求和的结果做与运算(&)。求最终结果的最大值。 思路: 将答案ans二进制表示,按位枚举,从最高位i开始,检查ans|(1< #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; typedef map M; typedef queue Q; typedef set S; typedef vector V; const int maxn=100; bool dp[maxn][maxn]; ll pre[maxn]; bool is_exist(ll x,int n,int m) { memset(dp,0,sizeof(dp)); for (int i=1;i<=n;++i) { if ((pre[i]&x)==x) //对于只分一段的情况,判断和是否包含x即可 dp[i][1]=1; for (int j=1;j>n>>k; for (i=1;i<=n;++i) { ll a; cin>>a; pre[i]=pre[i-1]+a; } ll ans=0; for (i=60;i>=0;--i) //从高位枚举 { if (is_exist(ans|(1ll<
原文地址:https://www.cnblogs.com/orangee/p/9116238.html