Ada and Coins

题意:钱包里有n种钱,然后有m次询问,询问[l,r]区间内能被表示的个数有几个。

题解:这道题是群主推荐我写的,然后让我用bitset去写,他说 操作32个bitset需要的时间 == 操作一个int所需要的时间, 所以有些题目用bitset去处理就能快了。

 这道题目的思路就是瞎几把乱写, 然后求一个前缀和就好了。

  

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
bitset<N> b;
int tot[N];
int main(){
//Fopen;
b[] = ;
int n, m;
scanf("%d%d", &n, &m);
int t;
for(int i = ; i <= n; i++){
scanf("%d", &t);
b |= (b << t);
}
tot[] = ;
for(int i = ; i < N; i++)
tot[i] = tot[i-] + b[i];
int l, r;
while(m--){
scanf("%d%d",&l,&r);
printf("%d\n",tot[r] - tot[l-]);
}
return ;
}

Ada and Coins的更多相关文章

  1. [LeetCode] Arranging Coins 排列硬币

    You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...

  2. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  3. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  4. csuoj 1119: Collecting Coins

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec  Memo ...

  5. Coins

    Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hi ...

  6. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  8. POJ3260The Fewest Coins[背包]

    The Fewest Coins Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6299   Accepted: 1922 ...

  9. POJ1742 Coins[多重背包可行性]

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 34814   Accepted: 11828 Descripti ...

随机推荐

  1. 利用dockerfile 安装一个nginx-1.14.1

    FROM docker.io/centos MAINTAINER jim 107420988@qq.com ENV TZ "Asia/Shanghai" #ENV TERM xte ...

  2. Spring Boot简单环境搭建

    #### 一.创建一个简单的Maven项目 使用`Maven`,通过导入`Spring Boot`的`starter`模块,可以将许多程序依赖的包自动导入到工程中.使用`Maven`的`parent ...

  3. HTML 第4章初始CSS3

    什么是CSS? CSS全称为层叠样式表,通常又称为风格样式表. 引用CSS样式: 语法: <h1 styske="color:red;">style属性的应用</ ...

  4. lvs+keepalived 高可用及负载均衡

    一.环境准备 VIP:10.18.43.30 dr1:10.18.43.10 dr2:10.18.43.20 web1:10.18.43.13 web2:10.18.43.14 结构图 (一).预处理 ...

  5. 怎么把PicPick设置成中文版?

    1.首先打开软件 2.在File文件中中点击能看到Program Options这一选项,单击打开 3.右下方有个Language选项,改成简体中文

  6. Vue-Router中History模式

    目录 history路由 官方示例 Express中间件 客户端兜底404 示例代码托管在:http://www.github.com/dashnowords/blogs 博客园地址:<大史住在 ...

  7. idea2019.2安装指南

    先去官网下载idea官网地址 下载UItimate版本点击 DOWNLOAD等待下载完成 点击ideaIU-2019.2.exe一路next      可以在这一步选一下 继续next         ...

  8. 记录一次Jquery中 this 关键字使用出现的问题

    今天在用Jquery改造之前的JS代码过程中,遇到了一个让我懵逼了三小时的问题. 问题的关键在 this 的使用.在这里与大家分享一下.并且分享一下我做表单提交的检查代码 错误代码如下: $(&quo ...

  9. docker学习1:docker前世今生

    Docker简介 Docker是2013发起的一个项目,早在2013年,Docker自诞生起,就是整个技术界的明星项目,当时我还在上海实习,就在各种技术媒体上看到了Docker的介绍文章,很多技术媒体 ...

  10. 流程控制之while循坏

    流程控制之while循坏 一.语法 循环就是一个重复的过程,我们人需要重复干一个活,人岂不是要累死啊,而且还是那么-..的枯燥乏味,向我这样要的小年轻,不骚里骚气的行吗?那岂不是白白流浪了这么多年头, ...