Time Limit: 1s Memory Limit: 32MB

问题描述

Given a sequence 1,2,3,…,N, your job is to calculate the number of sub-sequences that the sum of the sub-sequence is M.

输入描述

The first line contains a single integer T(1≤T≤10), indicating the number of test cases. Each case contains two integers N,M(1≤N,M≤1000).

输出描述

For each case, print a number in a line.

输入样例

2

20 10

50 30

输出样例

2

4

样例解释

For the first case: the sum of sub-sequence [1, 4] and [10, 10] is 10.

【题目链接】:

【题解】



傻逼题



【完整代码】

#include <bits/stdc++.h>

using namespace std;

int main()
{
freopen("H.in","r",stdin);
freopen("H.out","w",stdout); int t;cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int ans=0;
for(int i=1;i<=n;++i)
{
int sum=0;
for(int j=i;j<=n;++j)
{
sum+=j;
if(sum==m)
ans++;
else if(sum>m)
break;
}
}
cout<<ans<<endl;
}
return 0;
}

【C++竞赛 H】The sum problem的更多相关文章

  1. 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...

  2. HDu 1001 Sum Problem 分类: ACM 2015-06-19 23:38 12人阅读 评论(0) 收藏

    Sum Problem Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. HDU 2058:The sum problem(数学)

    The sum problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. Problem-1001:Sum Problem

    Sum Problem Sample code : #include <stdio.h> int main() { int i,n; int sum; while(scanf(" ...

  5. NYOJ 927 The partial sum problem 【DFS】+【剪枝】

    The partial sum problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...

  6. summary of k Sum problem and solutions in leetcode

    I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com ...

  7. Subset sum problem

    https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...

  8. HD2058The sum problem

    The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  9. Maxmum subsequence sum problem

    We have a lot of ways to solve the maximum subsequence sum problem, but different ways take differen ...

  10. HDU 2058 The sum problem(枚举)

    The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the ...

随机推荐

  1. samba-设定文件共享

    家里有两台电脑,一台装的是window,一台装的是ubuntu.一直想要实现两台电脑资源共享,今天终于成功实现了. smaba 具体简介就不说了,反正就知道,它可以创建一个服务器,然后让其他的电脑共享 ...

  2. 数据库中解析XML

    简介:OPENXML方法使用一例实现导入功能 DECLARE @strProjGUID AS VARCHAR(50)  DECLARE @strProjCode AS VARCHAR(50)  DEC ...

  3. SQL2012的新分页方法

    SELECT BusinessEntityID , FirstName , LastName FROM Person.Person ORDER BY BusinessEntityID OFFSET ( ...

  4. 关于Webpack详述系列文章 (第四篇)

    1. webpack基本概念 Entry:入口,Webpack 执行构建的第一步将从 Entry 开始,可抽象成输入.Module:模块,在 Webpack 里一切皆模块,一个模块对应着一个文件.We ...

  5. BZOJ2329: [HNOI2011]括号修复(Splay)

    解题思路: Replace.Swap.Invert都可以使用Splay完美解决(只需要解决一下标记冲突就好了). 最后只需要统计左右括号冲突就好了. 相当于动态统计最大前缀合和最小后缀和. 因为支持翻 ...

  6. CISP/CISA 每日一题 22

    CISSP 每日一题(答)What should be done to verify patcheshave been applied? Auditpatches, or use a vulnerab ...

  7. [React] Call setState with null to Avoid Triggering an Update in React 16

    Sometimes it’s desired to decide within an updater function if an update to re-render should be trig ...

  8. Codeforces 559A Gerald&#39;s Hexagon 数三角形

    题意:按顺序给出一个各内角均为120°的六边形的六条边长,求该六边形能分解成多少个边长为1的单位三角形. 把单位三角形面积看做1,实际上就是求六边形面积.随便找六边形的三条互相不相邻的边,分别以这三条 ...

  9. jquery ui 分页插件 传入后台的连个參数名

    參数名: page .rows page=int(request.form.get('page',1).encode('u8')) rows1=int(request.form.get('rows', ...

  10. 84.setlocale

    用法示例 #include <Windows.h> #include <stdio.h> #include<locale.h> void main() { //se ...