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. java创建节点和单向链表

    package datastructure; public class Node { private Object data; private Node next; public Node() { t ...

  2. Java 批量修改文件后缀

    import java.io.*; public class test { public void reName(String path, String from, String to) { File ...

  3. 趣闻|Python之禅(The Zen of Python)

    在Python解释器中输入“import this”会发生什么?如果你不知道这个彩蛋,推荐继续阅读这篇文章. 2001年秋,Foretec(一家会议组织公司)正在准备召开第十届Internationa ...

  4. 有关 Lambda && linq练习 有待整理

    1. 查询Student表中的所有记录的Sname.Ssex和Class列.(select sname,ssex,class from student) Students.Select(s=> ...

  5. textview-显示行数限制

    在代码中直接添加 android:maxLines="2" android:ellipsize="end" 跟ellipsize搭配使用,超过两行的时候,第二行 ...

  6. what happens when changing the DOM via innerHTML

    what happens when changing the DOM via innerHTML

  7. ThinkPHP5.0---方法异常格式

    public function test(){ try{ // 获取到ThinkPHP的内置异常时,直接向上抛出,交给ThinkPHP处理 }catch (\think\Exception\HttpR ...

  8. 查看网站使用何种框架或者技术的插件——Wappalyzer

    Wappalyzer这款插件很强大,可以查看任何网站使用的技术,包括后端语言框架和前端语言框架.还有服务器是何种类型.甚至各种版本... 插件官网:https://wappalyzer.com/

  9. JPA的配置文件persistence.xml参数详解

    <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0&q ...

  10. ArcGIS 10.5 新功能

    ArcGIS 10.5正式发布,打造智能的Web GIS平台 2017年新年来临之际,ArcGIS 10.5正式发布. 历经几个版本,ArcGIS10.5已经革新为一个智能的以Web为中心的地理平台, ...