数论 - hdu5363 Key Set
来源:互联网 发布:淘宝金小姐正品代购 编辑:程序博客网 时间:2024/05/26 12:00
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=5363
题意:
集合S为{1,2..n},问S有多少个子集,满足集合中数字之和为偶数
思路:
记集合S中偶数个数为even,奇数个数为odd,集合中数字之和为奇数的子集数为2^even - 2 ^ (odd-1),总数为2^n,相减即可,因为n的数字过大需要使用快速幂
代码:
#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<math.h>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<map>#include<set>#include<functional>#pragma comment(linker, "/STACK:102400000,102400000")//C++using namespace std;const long long MOD = 1000000007;//return a^b%clong long quickpower(int a, int b, int c){long long ans = 1, pow = a;while (b){if (b & 1) ans = ans * pow % c;pow = (pow*pow) % c;b >>= 1;}return ans;}int main(){ long long n,total; cin>>total; while (total--){ scanf("%lld",&n); long long even = n/2, odd = n-even; long long ans = (((quickpower(2,n,MOD)-1) - quickpower(2,even,MOD) * quickpower(2,odd-1,MOD)) % MOD + MOD) % MOD; printf("%lld\n",ans); } return 0;}
0 0
- 数论 - hdu5363 Key Set
- HDU5363:Key Set
- Key Set(HDU5363)
- HDU5363:Key Set
- Key Set(快速幂+数学分析) HDU5363
- [快速幂,取模]HDU5363 多校联合第六场 Key set
- key set
- key set
- Set Key 设置键
- HDU 5363 Key Set
- HDU 5363 Key Set
- hdu 5363 Key Set
- HDU 5363 Key Set
- 多校6-Key Set
- HDU 5363 Key Set
- HDU 5363 Key Set
- HDOJ-5363 Key Set
- HDOJ 5363 Key Set
- UIButton的发现
- 设计模式之 工厂模式
- javaweb学习总结(十)——HttpServletRequest对象(一)
- 必须记住的30类选择器
- SpringMVC Controller 介绍
- 数论 - hdu5363 Key Set
- POJ 1094-Sorting It All Out(拓扑排序)
- 多线程 读取List
- 图结构练习——判断给定图是否存在合法拓扑序列
- ICP算法与RANSAC算法描述
- Android Fragment 真正的完全解析(下)
- 第1章 计算机系统概论--笔记
- width:100%
- Linux笔记--目录