Binary Indexed Tree实现 国内称作 树状数组
来源:互联网 发布:coc九本女王升级数据 编辑:程序博客网 时间:2024/05/17 04:47
国内资料:http://baike.baidu.com/view/1420784.htm
国外资料:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=binaryIndexedTrees
重点:
储存策略,更新策略,查找策略, x & (-x)的证明
数组从1开始
自己实现的代码如下:
#include <iostream>int const N = 1000;int tree[N];void updateBIT(int* a, int idx, int len){int val = a[idx];while(idx <= len){tree[idx] += val;idx += (idx & (-idx));}};void buildBIT(int* a, int len){memset(tree, 0, len * sizeof(int));for(int i = 1; i <= len; i++){updateBIT(a, i, len);}};int getSum(int idx){int sum = 0;while(idx > 0){sum += tree[idx];idx -= (idx & (-idx));}return sum;};int main(){int a[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};buildBIT(a, 20);for(int i = 1; i <= 20; i++){std::cout << "Sum[" << i << "] = " << getSum(i) << std::endl;}return 0;}
- Binary Indexed Tree实现 国内称作 树状数组
- 树状数组(Binary Indexed Tree)
- 树状数组(Binary Indexed Tree)
- 树状数组(Binary Indexed Tree)
- Binary indexed tree(树状数组)
- 树状数组(Binary Indexed Tree)
- 树状数组 Binary Indexed Tree
- 树状数组(binary indexed tree)
- 树状数组 Binary Indexed Tree
- 树状数组/Binary Indexed Tree/Fenwick Tree
- 树状数组(Binary Indexed Tree)
- POJ 2352 树状数组(Binary Indexed Tree)
- POJ 2481 树状数组(Binary Indexed Tree)
- poj3067 树状数组(Binary Indexed Tree)
- 树状数组 BIT (Binary Indexed Tree)
- 算法基础 - 树状数组(binary indexed tree)
- Binary Indexed Tree (树状数组)
- 树状数组(Binary indexed Tree)
- Android学习笔记————异步图片加载
- HDU 1560 DNA sequence IDA*搜索
- 设备驱动之一 - proc文件系统接口
- 多线程下的单例模式
- Android中的自定义数据适配器
- Binary Indexed Tree实现 国内称作 树状数组
- windows基本窗口
- CGI ASP PHP JSP ASP.net 比较
- 迈出从3K到1W的重要一步——掌握设计模式
- Comparator接口
- MBR完整架构
- Android Handler 主线程 子线程 双向通信
- 大数操作
- Windows内核技术的精华站点