Ada and Coins

 

Ada and Coins

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

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

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

  

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
 4 #define LL long long
 5 #define ULL unsigned LL
 6 #define fi first
 7 #define se second
 8 #define pb push_back
 9 #define lson l,m,rt<<1
10 #define rson m+1,r,rt<<1|1
11 #define max3(a,b,c) max(a,max(b,c))
12 #define min3(a,b,c) min(a,min(b,c))
13 typedef pair<int,int> pll;
14 const int INF = 0x3f3f3f3f;
15 const LL mod = 1e9+7;
16 const int N = 1e5+10;
17 bitset<N> b;
18 int tot[N];
19 int main(){
20     //Fopen;
21     b[0] = 1;
22     int n, m;
23     scanf("%d%d", &n, &m);
24     int t;
25     for(int i = 1; i <= n; i++){
26         scanf("%d", &t);
27         b |= (b << t);
28     }
29     tot[0] = 1;
30     for(int i = 1; i < N; i++)
31         tot[i] = tot[i-1] + b[i];
32     int l, r;
33     while(m--){
34         scanf("%d%d",&l,&r);
35         printf("%d\n",tot[r] - tot[l-1]);
36     }
37     return 0;
38 }
View Code

 

转载于:https://www.cnblogs.com/MingSD/p/8931389.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值