UVA11137(立方数之和)】的更多相关文章

题意:       给你一个n(<=10000),问他如果由立方数之和组成,那么有多少种方法? 思路:        一个地推公式,d[i][j] 表示用不大于i的数字去组合j这个数字有多少种方法,因为n<=10000所以i最大是21,最后答案就是d[21][n],地推公式是 d[i][j] = d[i-1][j] + d[i][j-i*i*i]; 可以这样理解,d[i-1][j]好说,就是不用当前这个数,d[i][j-i*i*i]表示的是用i,同时 for(i = j ;j <= n…
小水题再来一发 给定一个正整数n<=1e4,求将n写成若干个正整数立方和的方法数 典型的多阶段模型 f[i][j]表示当前用到1~i的数,累计和为j的方案数. #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> using namespace std; typedef long long LL; LL f[][]; int main() { //freopen(…
People in Cubeland use cubic coins. Not only the unit of currency iscalled a cube but also the coins are shaped like cubes and their valuesare cubes. Coins with values of all cubic numbers up to 9261(= 213),i.e., coins with the denominations of 1, 8,…
定义: 完全数:所有的真因子(即除了自身以外的约数)的和,恰好等于它本身.例如:第一个完全数是6,它有约数1.2.3.6,除去它本身6外,其余3个数相加,1+2+3=6.第二个完全数是28,它有约数1.2.4.7.14.28,除去它本身28外约数相加=28. 性质: (1)所有的完全数都是三角数.例如:6=1+2+3:28=1+2+3+...+6+7:496=1+2+3+...+30+31:8128=1+2+3…+126+127. (2)所有的完全数的倒数都是调和数.例如:1/1+1/2+1/3…
完数: 完全数(Perfect number),又称完美数或完备数,是一些特殊的自然数.它所有的真因子(即除了自身以外的约数)的和(即因子函数),恰好等于它本身.如果一个数恰好等于它的因子之和,则称该数为"完全数". 下面性质来自百度百科 1.所有的完全数都是三角形数 例如: 6=1+2+3 28=1+2+3+...+6+7 496=1+2+3+...+30+31 8128=1+2+3-+126+127 2.所有的完全数的倒数都是调和数 例如: 1/1+1/2+1/3+1/6=2 1/…
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the r…
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. 这道题让我们求一棵二叉树的所有左子叶的和,那么看到这道题我们知道这肯定是考二叉树的遍历问题,那么最简洁的写法肯定是用递归,由于我们只需要累加左子叶…
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target. Example: nums = [1, 2, 3] target = 4 The possible combination ways are: (1, 1, 1, 1) (1, 1, 2) (1,…
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target. For example, given nums = [-2, 0, 1, 3], and target = 2. Retu…
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Ensure that numbers within the set are sorted in ascending order. Example 1…
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead. For example, given the array [2,3,1,2,4,3] and s = 7,the subarray [4,3] has the minimal…
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. For example, 1 / \ 2 3…
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example:Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2], [5,8,4,5] ] 这道二叉树路径之和在之前的基础上又需要找…
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements in a quadruplet (a,b,c,d) must be in non-descending order.…
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For example, given array S = {-1 2…
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c) The solut…
一.设计思想 先将参数个数输出,并利用循环结果将参数逐个输出,再将字符串强制转化成整型,利用循环结构相加求和 二.程序流程图 三.源程序代码 package demo; public class CommandParameter {  /**  * @param args  */  public static void main(String[] args) {   // TODO Auto-generated method stub    int sum=0;                 …
用while语句求1~100之和 public class Ex3_5 {    public static void main(String[] args){        int n=1,sum=0;        while(n<=100)        {            sum+=n;            n++;        }        System.out.println("sum="+sum);    }}…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3448    Accepted Submission(s): 1144 Problem Description It has been ten years since TJU-ACM established. And in this year all the retired TJU-ACM…
求m到n之和 int sum(int m, int n) { int i, result = 0; for (i=m; i<=n; i++) result = result+i; return result; }…
题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积性函数前缀和的方法,学习参考博客:http://blog.csdn.net/skywalkert/article/details/50500009  要好好看大神的博客哦orz 用筛法预处理前N^(2/3)项,后面的记忆化搜索解决. 不太会用哈希,就用map记忆化一下: #include<cstdi…
求∑1<=i<=n∑1<=j<=ngcd(i,j) % P P = 10^9 + 7 2 <= n <= 10^10 这道题,明显就是杜教筛 推一下公式: 利用∑d|nphi(d) = n ans = ∑1<=i<=n∑1<=j<=n∑d|(i,j)phi(d) = ∑1<=d<=n∑1<=i<=n∑1<=j<=n[d|(i,j)]phi(d) = ∑1<=d<=nphi(d)∑1<=i<…
一. 在主函数中实现二维数组的输入. 代码主要函数maxson(),主要利用for()循环先查找出最大字数组的四角的坐标xmin,xmax,ymin,ymax来确定最大子数组, 在循环中算出之和,编写过程中行列的值赋值错误,但经过调试查找出来了:后来在输出最大子数组的地方遇到麻烦, 考虑不周全用普遍的  if(j%n==0)cout<<endl;来进行换行,导致出现错误,应改为if(j%n==m),m为最大子数组的第一列, 源代码: #include <iostream> usin…
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 3769  Solved: 1734[Submit][Status][Discuss] Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + - + k mod n的值,其中k mod i表示k除以i的余数.例如j(5, 3)=3 mod 1 + 3 mod 2 + 3 mod 3 + 3…
阶乘之和 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 给你一个非负数整数n,判断n是不是一些数(这些数不允许重复使用,且为正数)的阶乘之和,如9=1!+2!+3!,如果是,则输出Yes,否则输出No:   输入 第一行有一个整数0<m<100,表示有m组测试数据:每组测试数据有一个正整数n<1000000; 输出 如果符合条件,输出Yes,否则输出No; 样例输入 2 9 10 样例输出 Yes No 小误区:1.0!=1:            2…
阶乘之和 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 给你一个非负数整数n,判断n是不是一些数(这些数不允许重复使用,且为正数)的阶乘之和,如9=1!+2!+3!,如果是,则输出Yes,否则输出No:   输入 第一行有一个整数0<m<100,表示有m组测试数据:每组测试数据有一个正整数n<1000000; 输出 如果符合条件,输出Yes,否则输出No; 样例输入 2 9 10 样例输出 Yes No 打表先把前9个元素的阶乘算出来,然后从大到小贪心…
Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值,其中k mod i表示k除以i的余数.例如j(5, 3)=3 mod 1 + 3 mod 2 + 3 mod 3 + 3 mod 4 + 3 mod 5=0+1+0+3+3=7 Input 输入仅一行,包含两个整数n, k. Output 输出仅一行,即j(n, k). Sample Input 5 3 Sample Output 7 HINT 5…
Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your code should return the index of the first number and the index of the last number. (If their are duplicate answer, return anyone) Have you met this quest…
描述 给你一个非负数整数n,判断n是不是一些数(这些数不允许重复使用,且为正数)的阶乘之和,如9=1!+2!+3!,如果是,则输出Yes,否则输出No: 输入 第一行有一个整数0<m<100,表示有m组测试数据:每组测试数据有一个正整数n<1000000; 输出 如果符合条件,输出Yes,否则输出No; 样例输入 2 9 10 样例输出 Yes No #include <stdio.h> ] = {, , , , , , , , }; int main() { int m,…
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located within t…