【C++竞赛 H】The sum problem
2017-10-04 18:45
357 查看
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; }
相关文章推荐
- Nyoj 927 The partial sum problem[dfs]
- HDOJ HDU 2058 The sum problem ACM 2058 IN HDU
- 杭电2058-The sum problem
- 2013年山东省第四届ACM大学生程序设计竞赛 Problem A Rescue The Princess 向量法 水题
- The sum problem hdu 2058
- nyoj Thepartialsumproblem(DFS)
- Uva 101 the block problem 木块问题(算法竞赛经典入门)STL vector
- HDU 2058 The sum problem
- NYOJ 题目927 The partial sum problem(dfs,剪枝)
- Y - The sum problem
- nyoj 927 The partial sum problem(dfs)
- nyoj927 The partial sum problem(dfs)
- hdu 2058 The sum problem
- HDOJ1001 Sum Problem_C++
- The sum problem
- 杭电acm2058————The sum problem(C语言)
- *寒假水48—— The sum problem
- HDOJ 2058 The sum problem [效率分析]
- POJ1298_The Hardest Problem Ever_最难的问题_Caesar 密码_C++
- NYoj The partial sum problem(简单深搜+优化)