HDU5119 2014北京区域赛H DP
来源:互联网 发布:大卫芬奇电影知乎 编辑:程序博客网 时间:2024/06/05 15:21
给40个数,大小不超过100万,求异或和超过M的组合个数。
do[i][j]表示前i个数异或和是j的组合个数
然后就可以从i-1更新到i了,选第i个或者不选第i个,类似背包问题。
#include<iostream>#include<vector>#include<stdio.h>#include<math.h>#include<string.h>using namespace std;int A[50];int N,M;const int MAXN=1<<20;long long dp[42][MAXN+9];//前i(from 0)个异或和是j的组合的个数int big;long long solve(){ //for(int i=) int cnt=0; while(big>0){ big>>=1; cnt++; } int maxres=1<<cnt; memset(dp,0,sizeof(dp)); for(int i=0;i<N;i++){ for(int j=0;j<maxres;j++){ dp[i][j]=0; } } dp[0][A[0]]=1; dp[0][0]=1; for(int i=1;i<N;i++){ for(int j=0;j<maxres;j++){ dp[i][j]+=dp[i-1][j];//不用第i个 //dp[i][j^A[i]]+=dp[i-1][j]; dp[i][j]+=dp[i-1][j^A[i]]; //cout<<"dp"<<i<<" "<<j<<" "<<dp[i][j]<<endl; } } long long ans=0; //cout<<maxres<<" ?"<<M<<endl; for(int i=M;i<maxres;i++){ ans+=dp[N-1][i]; //cout<<"ans+"<<dp[N-1][i]<<endl; } return ans;}/*1002 1010 10*/int main(){ //cout<<(1<<20)<<endl; int T; cin>>T; for(int i = 0 ; i < T ; i++){ cin>>N>>M; big=0; for(int j=0;j<N;j++){ scanf("%d",&A[j]); big=max(big,A[j]); } cout<<"Case #"<<i+1<<": "<<solve()<<endl; } return 0;}
阅读全文
0 0
- HDU5119 2014北京区域赛H DP
- 2014年 acmicpc北京区域赛题目(hdu5112 hdu5119 hdu5120 hdu5122)
- HDU5119(DP)
- hdu5119 DP
- 2014 北京区域赛 F Fluorescent HDU5117 (数学+状压+dp)
- 2014 北京区域赛 F Fluorescent HDU5117 (数学+状压+dp)
- 10.1训练赛--北京14现场赛--HDU5119
- 2014 北京区域赛题目
- 第36届ACM 北京区域赛邀请赛 H题
- hdu5119(dp)
- hdu5119(dp)
- 2014 北京区域赛 F Fluorescent HDU5117 (数学+状压+dp)★ ★
- hdu4089 Activation 概率dp 2011北京区域赛
- HDOJ5119 Happy Matt Friends(状压dp) ——2014北京现场赛H题
- 2014年北京、广州区域赛总结
- hdu5119 Happy Matt Friends( DP )
- 2015acm区域赛北京
- acm2015北京区域赛游记
- pandas apply value_counts
- 【错误集锦】——java.math.BigDecimal cannot be cast to java.lang.String
- Linux Windows 双系统时无法挂载硬盘的解决方法
- leetcode-month2-week7
- Struts2的基本项目实现、简易使用方法
- HDU5119 2014北京区域赛H DP
- 面试经验小点
- 【MyBatis】整体理解
- LDA与PCA的对比
- shell编程之数值计算 seq命令
- Unhandled fault: external abort on non-linefetch (0x1818) at 0xb6f28200
- Ubuntu下OpenCV编程[3]-滑动条的使用
- 什锦披萨(人人网笔试)
- C++ 学习基础篇(一)—— C++与C 的区别