Codeforces 769D k-Интересные пары чисел
题目链接:http://codeforces.com/contest/769/problem/D
搜索题
考虑这些数的值域较小,直接${O(2^{k})}$次方枚举每个数字二进制位上是否改变,剪枝一下最不利复杂度为${O(C_{14}^{7})}$,有${10^{4}}$中取值。
最终最不利复杂度为${O(C_{14}^{7}*(10^{4}))}$
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 100010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,str[maxn],c[maxn],k,v[maxn];
vector<llg>a[maxn];
llg d[maxn];
void ss1(llg wz,llg res,llg x)
{
if (wz==)
{
if (res==)
{
llg val=;
for (llg i=;i<;i++) val+=(<<i)*((str[i]+c[i])%);
a[x].push_back(val);
}
return ;
}
if (res)
{
c[wz]=;
ss1(wz+,res-,x);
}
c[wz]=;
ss1(wz+,res,x);
} void ss2(llg wz,llg res,llg x)
{
if (wz==)
{
if (res==)
{
llg val=;
for (llg i=;i<;i++) val+=(<<i)*((str[i]+c[i])%);
a[x].push_back(val);
}
return ;
}
if (res)
{
c[wz]=;
ss2(wz+,res-,x);
}
c[wz]=;
ss2(wz+,res,x);
} void change_(llg x)
{
llg cs=;
while (cs<)
{
str[cs]=x%;
x/=;
cs++;
}
} int main()
{
yyj("D");
cin>>n>>k;
for (llg i=;i<=;i++)
{
change_(i);
if (k<=) ss1(,k,i);else ss2(,-k,i);
}
for (llg i=;i<=n;i++) scanf("%lld",&v[i]),d[v[i]]++;
llg ans=;
for (llg i=;i<=n;i++)
{
llg w=a[v[i]].size(),x=v[i];
for (llg j=;j<w;j++)
if (k==) ans+=d[a[x][j]]-; else ans+=d[a[x][j]];
}
cout<<ans/;
return ;
}
Codeforces 769D k-Интересные пары чисел的更多相关文章
- Codeforces gym102152 K.Subarrays OR
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...
- codeforces 1133E K Balanced Teams
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...
- Codeforces 1133E - K Balanced Teams - [DP]
题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...
- codeforces 1269E K Integers (二分+树状数组)
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...
- codeforces 1282B2. K for the Price of One (Hard Version) (dp)
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
- Codeforces 544E K Balanced Teams (DP)
题目: You are a coach at your local university. There are nn students under your supervision, the prog ...
- Codeforces Gym101502 K.Malek and Summer Semester
K. Malek and Summer Semester time limit per test 1.0 s memory limit per test 256 MB input standard ...
- Codeforces 769D
太久没写搜索因为递归边界问题卡了很久.. 题意:定义k-interesting:如果两个数的二进制形式有k位不相同,则称之为k-interesting.给出n和k,输入n个大小在[0,10000]之间 ...
- Codeforces 987 K预处理BFS 3n,7n+1随机结论题/不动点逆序对 X&Y=0连边DFS求连通块数目
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...
随机推荐
- Kattis之旅——Fractional Lotion
Freddy practices various kinds of alternative medicine, such as homeopathy. This practice is based o ...
- shell expr match
expr match "$pwrdm_stat" ".*,\($pwr_state:[0-9]*\)" 不理解 从字符串开始的位置匹配子串的长度 expr ...
- MMU工作原理(转)
源: MMU工作原理
- Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFa ...
- Linux学习笔记之在 CentOS 里下载 RPM 包及其所有依赖包
0x00 概述 前几天我尝试去创建一个仅包含我们经常在 CentOS 7 下使用的软件的本地仓库.当然,我们可以使用 curl 或者 wget 下载任何软件包,然而这些命令并不能下载要求的依赖软件包. ...
- android 颜色值参考,(有颜色图
) 2011-10-13 19:55:30| 分类: android | 标签:android颜色值|字号大中小 订阅 Android 常用RGB值以及中英文名称 颜 色 RGB值 英文名 中文名 ...
- sql存储过程算法
MSSQL执行 : exec proc_NAME ORACLE : beginproc_NAME;commit;end; 1.求素数 MSSQL; CREATE proc [dbo].[EXEC003 ...
- win7 下安装使用 nginx 出现500错误
配置虚拟主机域名后访问网站出现500错误,发现是因为路径的反斜杠问题,改成正斜杠后问题解决.
- Bugku-CTF之web基础$_GET
Day3 web基础$_GET http://123.206.87.240:8002/get/ 打开之后是一段代码
- DPAA1是如何辅助cpu进行网络加速的?
1.为何会出现DPAA1? 1.1 如果没有多核处理器的出现可能就不会出现这个东东了! 1.2 怎么会跟多核处理器扯上关系呢? 1.2.1 先聊聊单核处理器会怎么处理网络包呢? 单核同一时刻只能处理一 ...