Hdu 5496 Beauty of Sequence (组合数)
2015-10-12 15:55
344 查看
题目链接:
Hdu 5496 Beauty of Sequence
题目描述:
一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和。问:一个整数序列的所有子序列的完美序列和?
解题思路:
考虑位于i位置数字x的贡献值,假设x是子序列中连续相同数字的第一个,那么x对于i后面的数有2(n-i)个贡献值,对前面的数,要么不选取,要么选取结尾不为x的方案数目。
Hdu 5496 Beauty of Sequence
题目描述:
一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和。问:一个整数序列的所有子序列的完美序列和?
解题思路:
考虑位于i位置数字x的贡献值,假设x是子序列中连续相同数字的第一个,那么x对于i后面的数有2(n-i)个贡献值,对前面的数,要么不选取,要么选取结尾不为x的方案数目。
#include <map> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const LL maxn = 100010; const LL mod = 1000000007; LL a[maxn]; map<LL, LL>M; int main () { LL t, n; scanf ("%lld", &t); while (t --) { scanf ("%lld", &n); for (int i=0; i<n; i++) scanf ("%lld", &a[i]); LL sum, cnt, num; sum = cnt = 0; M.clear(); for (int i=0; i<n; i++) { num = (cnt + 1 - M[a[i]] + mod) % mod; sum = (2 * sum % mod + num * a[i] % mod) % mod; M[a[i]] = (M[a[i]] + cnt + 1) % mod; cnt = (cnt * 2 + 1) % mod; } printf ("%lld\n", sum); } return 0; }
相关文章推荐
- zoj 3911 Prime Query (ZOJ Monthly, October 2015 - I)
- 关于UITableView的section最后一个分割线的优化
- easyui表单提交,后台获取不到值
- When START-OF-SELECTION is Not Required
- Request获取url各种信息的方法
- iOS开发笔记-Autolayout自动布局与UIView动画
- id to load is required for loading----id被要求加载exception
- Flume学习9_log4j:ERROR setFile(null,true) call failed产生的一个原因
- UI-UIView
- The request sent by the client was syntactically incorrect (). 的某个解决办法
- jsp中国文字形式提交,request对象获取乱码
- iOS仿京东分类菜单之UICollectionView内容
- UVA-1612 Guess (贪心)
- Pop Sequence
- 关于UITableView多余分割线的优化
- 哈希+前缀和 hdu5496 Beauty of Sequence
- (ArcGIS API For Silverlight )QueryTask 跨层查询,和监控完整的查询!
- AdapterView类mBlockLayoutRequests、mInLayout变量简介
- silverlight中使用NavigationContext.QueryString动态加载文章
- 安卓中用迭代直接显示json中的key+value