lowbit
来源:互联网 发布:大排畸哪些数据看男女 编辑:程序博客网 时间:2024/05/21 05:42
lowbit
这个题先把它搞成二进制
可以发现异或出来在lowbit找的是最后一位为一的数的价值,而异或出来只有两种情况,1或0,
所以一开始把所有书分成两份,同分之间没有价值,只有异份之间有价值,且价值为2^t,就是最后一位不同的价值,找出同分异分之间有多少组合,就是多少个2^t
一步一步分,最后直到不能分了
像这样
1 2 3 4 5
001
010
011
100
101
001 010
011 100
101
322 1 = 12 010 100
112 2=4
011 001
101
122 * 2 = 8
101 001
112 * 4 = 8
#include<cstdio>#include<iostream>#define p 1000000007using namespace std;#define for(i,x,y) for(int i=x;i<=y;i++)#define ll long long int m;int a[110011];ll ans;int b[110099];#define D "%d"void work(int n,int x){ if(n<=1||x>29) return ; int t=0; for(i,1,n) if(a[i]&(1<<x)) b[++t]=a[i]; int w=t; for(i,1,n) if(!(a[i]&(1<<x))) b[++w]=a[i]; (ans+=1ll*t*(w-t)*2*(1<<x))%p; for(i,1,t) a[i]=b[i]; work(t,x+1); for(i,t+1,w) a[i-t]=b[i]; work(w-t,x+1);}int main(){ freopen("lowbit.in","r",stdin); freopen("lowbit.out","w",stdout); scanf(D,&m); for(i,1,m) scanf(D,&a[i]); work(m,0); printf("%lld",ans%p);}
阅读全文
1 0
- lowbit
- lowbit
- lowbit
- lowbit
- lowbit
- lowbit
- Lowbit Sum
- Lowbit Sum
- 关于lowbit
- 【lowbit(x)】
- x&(-x) Lowbit(x)
- x&(-x) Lowbit(x)
- ACdream 1154 Lowbit Sum
- poj 2309 BST(lowbit)
- ACdream1154(lowbit的理解)
- 位运算函数lowbit
- 先论lowbit
- lowbit函数 x&(-x)
- Game (子串问题 模板)
- AlarmManager闹钟管理器
- 管理文件输入输出
- 1009 数字1的数量
- 在控制器的Action中,如何直接使用JsonResult方法中传递到前台的对象
- lowbit
- Java中栈和队列
- springMVC从上传的Excel文件中读取数据
- 函数式编程
- 算法第四版Algorethms 4th学习笔记(1)
- TCP三次握手与四次握手
- Let's Chat
- 机器学习笔记(三) 随便实现的logistic回归
- LeetCode--Merge Two Sorted Lists