UOJ 110 [APIO2015]Bali Sculptures
来源:互联网 发布:卖血哥玩的软件是什么 编辑:程序博客网 时间:2024/05/09 04:13
贪心+二进制按位DP
我们需要让答案尽量小,即让答案的二进制位的高位尽量为0。可以一位一位做,同时要保证前面做过的位的答案不变。
前4个子任务,记f[i][j]表示前i个数分成j组,且符合当前答案的方案是否存在。那么它可以从一个合法的f[k][j-1] (k < i) 转移过来。这样是O(n^3*logn)的。
第5个子任务用上面的方法会T。考虑到A=1,即没有分组下界。记g[i]表示前i个数符合当前答案最少要分几组。那么它同样可以从一个合法的g[k]转移过来。这样是O(n^2)的。
#include<cstdio>#include<algorithm>#define N 2005#define ll long longusing namespace std;const int INF = 2333;int n, a, b, len=0, g[N];bool f[105][105];ll pre[N], pos, ans;void solve2(){ for(pos>>=1;pos;pos>>=1,len--) { f[0][0]=1; for(int i = 1; i <= n; i++) for(int j = 1; j <= i; j++) { f[i][j]=0; for(int k = 0; k < i; k++) { ll temp = pre[i]-pre[k]; if(f[k][j-1] && ((temp>>len)|ans)==ans && (temp&pos)==0) { f[i][j]=1; break; } } } ans<<=1; ans^=1; for(int i = a; i <= b; i++) if(f[n][i]) { ans^=1; break; } }}void solve1(){ for(pos>>=1;pos;pos>>=1,len--) { for(int i = 1; i <= n; i++) { g[i]=INF; for(int j = 0; j < i; j++) { ll temp = pre[i]-pre[j]; if(((temp>>len)|ans)==ans && (temp&pos)==0) { g[i]=min(g[i],g[j]+1); } } } ans<<=1; if(g[n]>b)ans^=1; }}int main(){ scanf("%d%d%d",&n,&a,&b); for(int i = 1; i <= n; i++) { scanf("%lld",&pre[i]); pre[i]+=pre[i-1]; } for(pos=1;pos<=pre[n];pos<<=1)len++; if(a!=1)solve2(); else solve1(); printf("%lld\n",ans);}
0 0
- UOJ 110 [APIO2015]Bali Sculptures
- [APIO2015]Bali Sculptures
- APIO2015 Bali Sculptures UOJ111 BZOJ4070
- [UOJ 110][APIO 2015]Bali Sculptures(按位DP)
- APIO2015 UOJ 110-112
- APIO2015 UOJ #110 - #112 题解
- [APIO] [最短路] [UOJ#111] APIO2015 Jakarta Skyscrapers
- UOJ 111 & BZOJ 4070 [Apio2015]雅加达的摩天楼
- UOJ 112 & BZOJ 4071 [Apio2015]巴邻旁之桥
- APIO2015
- Ice Sculptures
- APIO2015总结
- 【APIO2015】完跪记
- Glass/Bronze sculptures
- D. Ice Sculptures
- D. Ice Sculptures
- [CodeForces158D]Ice Sculptures[暴力]
- CF158D Ice Sculptures 【睡前水一发。。】
- UVa1585 Score
- Zend Stuiod 快捷键
- BSOJ4854 -- 【NOIP2016模拟1】noip2016十连测round1 Divisors
- Python装饰器学习<转载>
- 独立看门狗
- UOJ 110 [APIO2015]Bali Sculptures
- VM安装的三种网络模式
- Ubuntu14.04安装NVIDIA驱动后之后无法进入图形界面
- 进程通信-----消息队列
- C++实现文件夹复制
- [剑指offer学习心得]之:在O(1)时间删除链表结点
- 【安卓-自定义布局】安卓App开发思路 一步一个脚印(十二)实现自定义左右滚动的信息块-仿蘑菇街
- 国内一线互联网公司面试题
- Ajax请求下,sendRedirect无效的问题