当前位置:网站首页>写点dp
写点dp
2022-07-29 07:15:00 【一条小小yu】
题目描述
珍珍学习乘法时,发现4=2*2,9=3*3,…,而2不可能分解为二个相同整数的乘积,但可以分解为1*1+1*1。她想知道对任意的正整数n,把它分解为几个整数与自身相乘之和,有多少种方案呢?
输入
输入只有一行,该行只有一个正整数n。
输出
输出只有一行,该行只有一个正整数,表示总方案数。
样例输入 Copy
13样例输出 Copy
6提示
30%的数据,1≤n≤10;
80%的数据,1≤n≤300;
100%的数据,1≤n≤800。
二维dp
#include <bits/stdc++.h>
using namespace std;
int n,i,j;
int k;
int a[35];
int dp[905][905];
void solve()
{
dp[0][0]=1;
for(i=1;i<=30;i++)
{
for(j=0;j<=k;j++)
{
for(int t=0;t*a[i]<=j;t++)
{
dp[i][j]+=dp[i-1][j-t*a[i]];
}
}
}
printf("%d",dp[30][k]);
}
int main()
{
cin>>k;
for(i=1;i<=30;i++)
{
a[i]=i*i;
}
solve();
return 0;
}
一维dp
#include <bits/stdc++.h>
using namespace std;
int n,i,j;
int k;
int a[35];
int dp[905];
void solve()
{
dp[0]=1;
for(i=1; i<=30; i++)
{
for(j=k;j>=0;j--)//倒着写对的,正着写错的
{
for(int t=1; t*a[i]<=j; t++)
{
dp[j]+=dp[j-t*a[i]];
}
}
}
printf("%d",dp[k]);
}
int main()
{
cin>>k;
for(i=1; i<=30; i++)
{
a[i]=i*i;
}
solve();
return 0;
}
边栏推荐
- Practice of online problem feedback module (XVII): realize the online download function of excel template
- stm32 操作W25Q256 W25Q16 spi flash
- 2-unified return class dto object
- 1 - background project construction
- 【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK
- QT topic: basic components (button class, layout class, output class, input class, container class)
- log4qt内存泄露问题,heob内存检测工具的使用
- 一篇长文---深入理解synchronized
- What is the function of fileappender in logback?
- 5-integrate swagger2
猜你喜欢
NFT 的 10 种实际用途
Using C language to skillfully realize the chess game -- Sanzi chess
【MYSQL】-【子查询】
Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
Female graduate students do "mind mapping" and quarrel with their boyfriend! Netizen: the "king of infighting" in the quarrel
A long article --- in-depth understanding of synchronized
Comparison of advantages between can & canfd integrated test analysis software lkmaster and PCA Explorer 6 analysis software
Redis Basics
用户列表 圆形头像并跟随小板块
关于大龄读博的几点回答?
随机推荐
0 8 动态规划(Dynamic Programming)
js第四天流程控制(if语句和switch语句)
Gin service exit
Homebrew brew update doesn't respond for a long time (or stuck in updating homebrew...)
thinkphp6 实现数据库备份
Job 7.28 file IO and standard IO
NFT 的 10 种实际用途
Some learning and understanding of vintage analysis
女研究生做“思维导图”与男友吵架!网友:吵架届的“内卷之王”....
WPF nested layout case
【WPF】通过动态/静态资源实现语言切换
Introduction to logback appender
0 9 布隆过滤器(Bloom Filter)
Thoroughly understand kubernetes scheduling framework and plug-ins
Comparison of advantages between can & canfd integrated test analysis software lkmaster and PCA Explorer 6 analysis software
Reflect reflect
【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
【暑期每日一题】洛谷 P4413 [COCI2006-2007#2] R2
@RequestMapping 用法详解
gcc/g++的使用