BestCoder Round #74 (div.2) T3 Transform HDOJ 5637
来源:互联网 发布:sql语言设计登陆验证码 编辑:程序博客网 时间:2024/05/22 03:09
/*
这道题有两种变化选择,一种翻转某一位很好办,对于另一种亦或操作:由于亦或有交换律,所以x^…^..=y也就等价于…^..=x^y,那就很好办,直接不停亦或就好啦O(∩_∩)O~
*/
# include < iostream > # include < cstring > # include < cstdio >using namespace std;typedef long long ll;int dp[1<<17],a,T,n,m,si,ti;//1<<17大概就是13万多,对于这道题一万是足够的,dp[i]就代表已经亦或到i的时候的最小次数;ll ans,mod=1e9+7;int main(){ cin>>T; while(T--) { ans=0; for(int i=1;i<=(1<<17);i++) { dp[i]=mod; }//因为要求最小,先将数组设为一个大数; dp[0]=0;//但是当j亦或它本身的时候会得到0,必须把dp[0]=0; scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) { scanf("%d",&a);//边输入便处理; for (int j=1;j<(1<<17);j++) { for (int k=0;k<17;k++) { dp[j]=min(dp[j],dp[j^(1<<k)]+1);//这就是翻转其中的某一位; } dp[j]=min(dp[j],dp[j^a]+1);//这是亦或可选的数字; } } for(int i=1;i<=m;i++) { scanf("%d%d",&si,&ti); ans=(ans+ll(i)*ll(dp[si^ti]))%mod; } printf("%I64d\n",ans); }}
(膜拜szc大神)
0 0
- BestCoder Round #74 (div.2) T3 Transform HDOJ 5637
- BestCoder Round #74 (div.2 c) hdu5637 Transform 【spfa】
- BestCoder Round #74 (div.2) T2 DFS HDOJ 5636
- BestCoder Round #74 (div.2) T4 Toposort HDOJ 5638
- hdu 5637 BestCoder Round #74 (div.2)
- BestCoder Round #74 (div.2)
- BestCoder Round #75 T3 King's Order HDOJ 5642
- BestCoder Round #54 (div.2) HDOJ 5429 Geometric Progression(模拟)
- hdoj BestCoder Round #81 (div.2) AA Machine
- hdoj 【BestCoder Round #81 (div.2)】 5670 Machine
- hdu5635 BestCoder Round #74 (div.2)
- BestCoder Round #74 (div.2) LCP Array
- BestCoder Round #74 (div.2)【1排列组合】
- BestCoder Round #11 (Div. 2)
- BestCoder Round #11 (Div. 2)
- BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round 50 (div 2)
- Activity的启动模式
- Servlet过滤器Filter使用 .
- webservice小例子
- 文章标题
- 自考C++程序设计试题2010年1月
- BestCoder Round #74 (div.2) T3 Transform HDOJ 5637
- phpcmsV9后台审核内容增加删除修改内容选项!
- 查看apk签名信息方法
- uva108 - - Maximum Sum (最大连续子矩阵和)
- POJ 2528
- 什么是android Service?
- STL sort源码剖析
- jquery data
- MySQL学习笔记4(索引)