P1679题目链接
可以使用DP去做,当做“完全背包问题”问题来处理。
初值: f [ 0 ] = 0 f[0]=0 f[0]=0
c o s t [ ] cost[] cost[] : c o s t [ i ] = i ∗ i ∗ i ∗ i cost[i] = i*i*i*i cost[i]=i∗i∗i∗i
状态转移方程: f [ j ] = M a t h . m i n ( f [ j ] , f [ j − c o s t [ i ] ] + 1 ) f[j] = Math.min(f[j], f[j-cost[i]]+1) f[j]=Math.min(f[j],f[j−cost[i]]+1)
AC代码(Java语言描述)import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
scanner.close();
int[] f = new int[num+1];
Arrays.fill(f, (int)1e8);
f[0] = 0;
int limit = (int)Math.pow(num, 0.25);
int[] cost = new int[limit+1];
for (int i = 0; i
关注
打赏
- 【Linux】Ubuntu20.04安装和卸载MySQL8
- 【Linux】Ubuntu 20.04 报错 curl: (23) Failure writing output to destination 的解决方法
- 【Java】JUnit 4.13.2 警告 ‘assertEquals(double, double)‘ is deprecated 的解决方法
- 【JavaScript】处理 @parcel/transformer-js: Browser scripts cannot have imports or exports.
- 【Node.js】Windows环境安装配置NVM和Node.js
- 【Python】处理TypeError: Plain typing.NoReturn is not valid as type argument
- 【Python】Matplotlib可视化50例
- 【C语言】C语言修改MySQL数据库
- 【Java】从默认包导入类和对象报错的解决方法
- 【Java】panel.getGraphics()报错空指针异常的解决方法