描述 One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N integers and the sum of them is equal to K.  输入 There are multiple test cases. Each test case contains three lines.The fir…
/* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 NYOJ--1058--dfs--部分和问题 基本一致,递归的i+1注意了,其他没什么 */ #include<cstring> #include<iostream> using namespace std; void dfs(int); ],vis[]; int n,k,sum,fla…
The partial sum problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N integers and the sum of them is equal to K. 输入 There are mul…
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927 代码: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <algorithm> #include <iostream> using namespace std; int n,k; ]; ; ]…
算法:搜索 描述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N integers and the sum of them is equal to K. 输入There are multiple test cases. Each test case contains three lines.The…
描述 One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choose some integers from the N integers and the sum of them is equal to K. 输入 There are multiple test cases. Each test ≤N≤),represents the array contains…
Partial Sum Accepted : Submit : Time Limit : MS Memory Limit : KB Partial Sum Bobo has a integer sequence a1,a2,…,an of length n. Each time, he selects two ends ≤l<r≤n and add |∑rj=l+1aj|−C into a counter which is zero initially. He repeats the selec…
Sum Problem Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 338086    Accepted Submission(s): 85117 Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this pro…
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12422 Accepted Submission(s): 3757 Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub…
原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://162.105.81.202/course/problemSolving/ 可以找到解题报告.<算法艺术与信息学竞赛>的习题提示在网上可搜到 一.动态规划参考资料:刘汝佳<算法艺术与信息学竞赛><算法导论> 推荐题目:http://acm.pku.edu.cn/JudgeOnl…
  继续讲故事~~   上次讲到我们的主人公丁丁,用神奇的动态规划法解决了杂货店老板的两个找零钱问题,得到了老板的肯定.之后,他就决心去大城市闯荡了,看一看外面更大的世界.   这天,丁丁刚回到家,他的弟弟小连就拦住了他,"老哥,有个问题想请教你."对于一向数学见长的小连,这次竟然破天荒的来问自己问题,丁丁感到不可思议:他俩一个以计算机见长,一个以数学见长,各自心里都有点小骄傲,不会轻易地向对方问问题.丁丁迟疑了一会儿,慢慢说道:"有什么问题是我们数学小天才解决不了的?&qu…
I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com/blog/summary-of-ksum-problems.html…
https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an important problem in complexity theory and cryptography. The problem is this: given a set (or multiset) of integers, is there a non-empty subset whose…
We have a lot of ways to solve the maximum subsequence sum problem, but different ways take different time. 1.Brute-force algorithm int maxSubSum1(const vector<int> &a) { int maxSum=0; for(int i=0;i<a.size();i++) for(int j=i;j<a.size();j++…
The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M.   Input Input contains multiple test cases. each case contains two integers N, M( 1 <=…
The sum problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 31453    Accepted Submission(s): 9414 Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the possib…
Sum Problem Sample code : #include <stdio.h> int main() { int i,n; int sum; while(scanf("%d",&n)!=EOF) { sum=; ;i<=n;i++) sum+=i; printf("%d\n\n",sum); } ; }…
Partial Sum Accepted : 80   Submit : 353 Time Limit : 3000 MS   Memory Limit : 65536 KB  Partial Sum Bobo has a integer sequence a1,a2,…,an of length n . Each time, he selects two ends 0≤l<r≤n and add |∑rj=l+1aj|−C into a counter which is zero initia…
C++ 的 STL 库的 <numeric> 头文件的 partial_sum 函数已实现了对某一序列的 partial sum. partial_sum(first, last, dest); 1. 部分和的引入 并非什么高级深奥的技巧,但却十分有用. 假设按照降序排列 N 个学生的考试成绩并保存到数组 scores[],现在想要编写求出从第 a 名到第 b 名成绩的函数 average(a, b),最简单的方法是,将 scores[a] 到 scores[b] 的乘积全部相加,然后除以 b…
代码参考:http://www.hankcs.com/program/uva-q101-the-blocks-problem.html Description Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics…
这一段时间一直都在刷OJ,这里建一个博客合集,用以记录和分享算法学习的进程. github传送门:https://github.com/haoyuanliu/Online_Judge/tree/master/HangDianOJ   Problem Description In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series…
Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他.   Input 第一行整数T,表示测试组数.后面T行,每行一个整数 n (1<=|n|<=10^5).   Output 输出1/n. (是循环小数的,只输出第一个循环节).   Sample Input 4 2 3 7 168   Sample Output 0.5 0.3 0.142857 0.005952380 和我名字那么相近的…
一.题目 http://acm.wust.edu.cn/problem.php?id=1192&soj=0 二.分析 要求从序列1,2,3,,,N,中截取一部分使他们的和为M 输入多组数据 输入0 0结束 每组数据结束有一个空行 三.思路 定义i,j,且1<=i<=j<=N,计算从i至j的数据的和sum,sum=(i+j)*(j-i+1)/2,sum与M比较,若相等则输出i,j.当输入100000 100000时,运行的时间较长(我没提交不知道有没有超时). 改进一下,1<…
Problem Description Given a sequence 1,2,3,--N, your job is to calculate all the possible sub-sequences that the sum of the sub-sequence is M. Input Input contains multiple test cases. each case contains two integers N, M( 1 <= N, M <= 1000000000).i…
2017江苏省赛的E题,当时在场上看错了题目没做出来,现在补一下…… 题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1264(注意在上面使用G++编译的话,请使用%I64d) Time Limit : 3000 MS Memory Limit : 65536 KB Bobo has a integer sequence a1,a2,…,an of length n. Each time, he selects…
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个新的字符串,i 属于[0,strlen(str)]如果新的字符串出现过ans++,例如:acmacm n=3,那么 子串为acm cma mac acm ,只有acm出现过 求ans; 输入 LINE 1: T组数据(T<10)LINE 2: n ,n <= 10,且小于strlen(str);L…
Problem Description In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.   Input The input will consist of a series of integers n, one integer per line.   Output For each case, output SUM(n) in one line, followed by a blank line.…
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=860 My思路: 先用两个字符串储存这两个实数,然后再用另外两个字符串储存去掉符号和前后多余的0后的新"实数",最后只需要比较两个化简后的新字符就ok了. My代码实现: #include<iostream> using namespace std; string simplify(string s) { //去字符串s的正负号和首尾多余的0 string a; ,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 题目大意就是把一段序列里面的数替换成f(x),然后让总和最大. 首先可以计算出初始的总和,以及每一个值换成f(x)的增益a[x]. 那么就是求一段子序列a[x]的最值了,经典的DP. 其实我一开始想到这个思路是因为列了一个式子: S = sum(n)-sum(rt)+sum’(rt)-sum’(lt)+sum(lt) =sum(n)+(sum’(rt)-sum’(lt))-(sum(rt)-s…
POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu   Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representati…