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 ...
随机推荐
- pytorch(16)损失函数(二)
5和6是在数据回归中用的较多的损失函数 5. nn.L1Loss 功能:计算inputs与target之差的绝对值 代码: nn.L1Loss(reduction='mean') 公式: \[l_n ...
- RabbitMQ初步使用,简洁介绍。
RabbitMQ是一种越来越流行的开源,快速消息代理,它使用Erlang编写并基于Open Telecom Platform框架构建.它实现了高级消息队列协议(AMQP),用于在进程,应用程序和服务器 ...
- python多线程参考文章
1. https://www.jianshu.com/p/c93e630d8089 2.https://www.runoob.com/python/python-multithreading.html ...
- IntelliJ IDEA报错总结
不能运行java程序 可能是没有选择运行环境点击 edit Configurations在Use classpath of module 中选择本项目的运行环境 Run报错: Error:java: ...
- ASP.NET .Core 集成 React SPA 应用
AgileConfig的UI使用react重写快完成了.上次搞定了基于jwt的登录模式(AntDesign Pro + .NET Core 实现基于JWT的登录认证),但是还有点问题.现在使用reac ...
- 2018ICPC南京I. Magic Potion
题目: 题意:n个士兵打m个怪兽,每个士兵只能打一个,但是如果有魔法药水就可多打一个问最多能打几个. 题解:如果没有魔法药就是一道裸二分图,因为现在有魔法要我们可以这样建图: 多建一个i+n的节点存放 ...
- POJ2635(数论+欧拉筛+大数除法)
题目链接:https://vjudge.net/problem/POJ-2635 题意:给定一个由两个质数积的大数M和一个数L,问大数M的其中较小的质数是否小于L. 题解:因为大数M已经超过long ...
- 《逆向工程核心原理》——DLL注入与卸载
利用CreateRemoteThread #include <iostream> #include <tchar.h> #include <Windows.h> # ...
- c++ 反汇编 数组和指针
字符串初始化字符数组 58: char as[] = "hello word"; 00AC7308 A1 70 2E B6 00 mov eax,dword ptr [string ...
- Python数据分析入门(一):搭建环境
Python版本: 本课程用到的Python版本都是3.x.要有一定的Python基础,知道列表.字符串.函数等的用法. Anaconda: Anaconda(水蟒)是一个捆绑了Python.cond ...