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 ;j ++)正着跑还能是的i用多次,想起了01和完全背包。
#include<stdio.h>
#include<string.h>
long long d[23][10005];
void solve()
{
for(int i = 1 ;i <= 10000 ;i ++)
d[1][i] = 1;
for(int i = 1 ;i <= 21 ;i ++)
d[i][0] = 1;
for(int i = 2 ;i <= 21 ;i ++)
for(int j = 1 ;j <= 10000 ;j ++)
{
d[i][j] = d[i-1][j];
if(j - i * i * i >= 0)
d[i][j] += d[i][j-i*i*i];
}
}
int main()
{
int n;
solve();
while(~scanf("%d" ,&n))
{
printf("%lld\n" ,d[21][n]);
}
return 0;
}
UVA11137(立方数之和)的更多相关文章
- [uva11137]立方数之和·简单dp
小水题再来一发 给定一个正整数n<=1e4,求将n写成若干个正整数立方和的方法数 典型的多阶段模型 f[i][j]表示当前用到1~i的数,累计和为j的方案数. #include<cstdi ...
- UVA - 11137 Ingenuous Cubrency[背包DP]
People in Cubeland use cubic coins. Not only the unit of currency iscalled a cube but also the coins ...
- 找出n之内的完全数, 并输出其因子
定义: 完全数:所有的真因子(即除了自身以外的约数)的和,恰好等于它本身.例如:第一个完全数是6,它有约数1.2.3.6,除去它本身6外,其余3个数相加,1+2+3=6.第二个完全数是28,它有约数1 ...
- java基础之完数判断
完数: 完全数(Perfect number),又称完美数或完备数,是一些特殊的自然数.它所有的真因子(即除了自身以外的约数)的和(即因子函数),恰好等于它本身.如果一个数恰好等于它的因子之和,则称该 ...
- [LeetCode] 4Sum II 四数之和之二
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such t ...
- [LeetCode] Sum of Left Leaves 左子叶之和
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...
- [LeetCode] Combination Sum IV 组合之和之四
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- [LeetCode] 3Sum Smaller 三数之和较小值
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 < ...
- [LeetCode] Combination Sum III 组合之和之三
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
随机推荐
- Docker搭建HAproxy+tomcat 实现高可用
构建业务镜像1创建tomcat-app1和tomcat-app2两个目录,代表不同的两个基于tomcat的业务.准备tomcat的配置文件[root@localhost ~]#mkdir -p /da ...
- mysql内一些可以布尔盲注的查询语句
一.left() 首先需要 use security; 这个数据库,然后进入之后再使用查询语句: 此时再使用: select left(database(),1)='s'; ...
- 通达OA 越权访问-2013/2015版本
漏洞参考 http://wiki.0-sec.org/0day/%E9%80%9A%E8%BE%BEoa/9.html 复现 根据⽹上的通达 OA的源码找这些敏感地址,如: /general/syst ...
- List调用toString()方法后,去除两头的中括号
import org.apache.commons.lang.StringUtils; public class Test { public static void main(String[] ...
- 我的2019年总结和一些2020年的flag
我的2019年总结和一些2020年的flag 前言 2019年在我的人生中注定是里程碑的一年,主要是我毕业了.本篇总结主要聊一些2019年经历的事以及对于自己2020年的期待 1. 再见2019 1. ...
- python获取到本机的公网IP
5行代码获取到本机的公网IP from urllib.request import urlopen import re text = str(urlopen("http://txt.go.s ...
- vs - 调试的技巧
在自助和局部变量窗口中固定属性 https://docs.microsoft.com/zh-cn/visualstudio/debugger/autos-and-locals-windows?view ...
- android分析之Binder 01
终于还是得写一篇关于Binder的文章了.从最初接触Android到花大把时间研究Android源码,Binder一直是分析道路的拦路虎.看了几本最流行的Android源码分析书籍,每次基本上都不能把 ...
- Educational Codeforces Round 64 C. Match Points 【二分思想】
一 题面 C. Match Points 二 分析 根据题意很容易想到要去找满足条件的数,因为可以打乱输入的顺序,所以很容易想到二分. 但是如果直接对输入的数组进行二分,如输入$a$,直接在数组里二分 ...
- 【linux】制作deb包方法 **
目录 前言 概念 ** 创建自己的deb包 文件源码 前言 制作deb的方式很多 使用 dpkg-deb 方式 使用 checkinstall 方式 使用 dh_make 方式 修改原有的 deb 包 ...