hdu 5496 Beauty of Sequence 组合数学
2015-10-04 22:14
381 查看
挺简单的一道组合数学,每个数字a单独看(设位置为p),有 2^(n-1)不同的序列会包含自己,但是要减掉自己前驱是a的情况,设前驱的位置是x,这种情况有 2^(x^1) * 2^(n-p)种排列,对每个数求前驱是a的情况的加和即可
看代码吧,cnt[k] = sigma(2^(x-1)) (a[x] == k)
最后结果是每个数字的值与unique后包含自己的情况总数的乘积和
看代码吧,cnt[k] = sigma(2^(x-1)) (a[x] == k)
最后结果是每个数字的值与unique后包含自己的情况总数的乘积和
#pragma warning(disable:4996) #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long LL; const LL mod = 1000000007; const int maxn = 100005; int b[maxn],a[maxn]; int n,m; LL cnt[maxn]; LL B[maxn]; int main() { int t; cin >> t; B[0] = 1; for (int i = 1;i < maxn;i++) B[i] = (B[i - 1] * 2) % mod; while (t--) { memset(cnt, 0, sizeof(cnt)); cin >> n; for (int i = 0;i < n;i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(b, b + n); m = unique(b, b + n) - b; LL ret = 0; for (int i = 0;i < n;i++) { int x = lower_bound(b, b + m, a[i]) - b; ret = ((ret - ((cnt[x] * (LL)a[i]) % mod * B[n - i - 1])%mod)%mod+mod)%mod; ret = (ret + B[n - 1] * (LL)a[i]) % mod; cnt[x] = (cnt[x] + B[i])%mod; } cout << ret << endl; } return 0; }
相关文章推荐
- UIMenuController的使用
- Android UI ActionBar功能-在 Action Bar 上添加按钮
- Android UI ActionBar功能-在 Action Bar 上添加按钮
- UITableViewCell
- iOS编程-------UITextField UIButton UITextFieldDelegate
- Android UI ActionBar功能-启动ActionBar
- Android UI ActionBar功能-启动ActionBar
- iOS编程-------UIView
- 我写了一个高并发的BlockingQueue,有兴趣的可以看看
- mysql query cache用法与性能详细介绍
- FreeSWITCH安装报错“You must install libyuv-dev to build mod_fsv”的解决方案
- UI课程14 标签视图控制器 UITabBarController
- iOS编程------UILabel
- hdoj 5496 Beauty of Sequence 【求序列所有子序列(去重后)的和】【好题】
- valueOf intValue parsetInt区别
- Handler、Message、MessageQueue、Looper关系及源码分析
- UI课程12 模态viewController,单例及单例模式
- iOS常用UI控件熟悉
- KVO(Key-Value-Observer)键值观察者
- UITableViewCell加载图片