传送门

Solution

折半搜索裸题,注意\(long long\)

Code

#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define Re register
#define Fo(i,a,b) for(Re int i=(a),_=(b);i<=_;i++)
#define Ro(i,a,b) for(Re int i=(b),_=(a);i>=_;i--)
using namespace std;
typedef long long LL; inline LL read() {
LL x=0,f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
return x*f;
} const int N=45;
LL n,m,k,t1,t2,ans;
LL da[N],s1[1050000],s2[1050000]; void dfs1(int pos,LL s) {
if(s>m) return ;
if(pos==k+1) {s1[++t1]=s;return ;}
dfs1(pos+1,s); dfs1(pos+1,s+da[pos]);
} void dfs2(int pos,LL s) {
if(s>m) return ;
if(pos==n+1) {s2[++t2]=s;return ;}
dfs2(pos+1,s); dfs2(pos+1,s+da[pos]);
} int main() {
n=read(),m=read();k=n/2;
Fo(i,1,n) da[i]=read();
dfs1(1,0);dfs2(k+1,0);
sort(s1+1,s1+1+t1); sort(s2+1,s2+1+t2);
LL p1=1,p2=t2;
while(p1<=t1&&p2) {
while(p2&&s1[p1]+s2[p2]>m) p2--;
ans+=p2; p1++;
}
printf("%lld\n",ans);
return 0;
}

最新文章

  1. hive 基本语法
  2. 【Java每日一题】20161125
  3. 黑马程序员——【Java基础】——正则表达式
  4. WindowsPhone-GameBoy模拟器开发五--使用XNA初略实现Gameboy显示系统
  5. Struts2 Annotation 注解配置
  6. VC下载文件显示进度条
  7. Ubuntu 系统 文件操作命令
  8. JPA 系列教程1-环境搭建
  9. 最新最全的html5标签集合
  10. (七)大图展示Demo引出的UIScrollView的使用
  11. [原创] debian 9.3 搭建seafile企业私有网盘
  12. python 在.py文件中调用其他.py内的函数
  13. MySQL 大致测试更新时间
  14. 重要, 要播放音乐视频等多媒体: 安装fedora23中的多媒体编码器
  15. docker图形化管理工具portainer
  16. 科学-天文学-天文观测站:TMT(红外天文望远镜)
  17. 整理一些常用的前端CND加速库,VUE,Jquery,axios
  18. ubuntu安装mongo数据库
  19. [UE4]让AI跑起来
  20. Vibrator震动

热门文章

  1. Java判断是否为移动端
  2. select readonly 不能看到其它选项解决方式
  3. Hypercall
  4. IOS 京东相关app 出现“网络请求失败,请检查您的网络设置”的解决办法
  5. Google Deepmind AI tries it hand at creating Hearthstone and Magic: The Gathering cards
  6. iOS网络开发工具集----字符串操作和时间操作
  7. Appium + python - automator定位升级版操作
  8. Springboot统一跨域配置
  9. [NOI2015,LuoguP2146]软件包管理器------树剖
  10. 三星的Knox Warranty Bit原理