当前位置:网站首页>Write some DP
Write some DP
2022-07-29 07:33:00 【A little Yu】
Title Description
When Zhenzhen learns multiplication , Find out 4=2*2,9=3*3,…, and 2 It is impossible to decompose into the product of two identical integers , But it can be broken down into 1*1+1*1. She wants to know for any positive integer n, Divide it into several integers and multiply it by itself , How many options are there ?
Input
There is only one line of input , This line has only one positive integer n.
Output
There is only one line of output , This line has only one positive integer , Represents the total number of schemes .
The sample input Copy
13Sample output Copy
6Tips
30% The data of ,1≤n≤10;
80% The data of ,1≤n≤300;
100% The data of ,1≤n≤800.
A two-dimensional 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;
}A one-dimensional 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--)// Write it right upside down , It's written incorrectly
{
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;
}
边栏推荐
- 信用卡购物积分
- Reflect reflect
- MySQL uses the client and select methods to view the summary of blob type fields
- Use custom annotations to verify the size of the list
- Dilworth 定理
- do end用法的妙处
- Synchronous / asynchronous, blocking / non blocking and IO
- Does Flink support sqlserver databases? Get the changes of SQLSERVER database
- 使用自定义注解校验list的大小
- PAT甲级 1146 拓扑顺序
猜你喜欢

LANDSCAPE

利用C语言巧妙实现棋类游戏——三子棋

QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)

梳理市面上的2大NFT定价范式和4种解决方案

MySQL如何把行转换为列?

MySQL uses the client and select methods to view the summary of blob type fields

How does MySQL convert rows to columns?

美智光电IPO被终止:年营收9.26亿 何享健为实控人

Use custom annotations to verify the size of the list

Job 7.28 file IO and standard IO
随机推荐
Pat class a 1150 traveling salesman problem
我想问一下,我flink作业是以upsert-kafka的方式写入数据的,但是我在mysql里面去更
多线程购物
[summer daily question] Luogu p4414 [coci2006-2007 2] ABC
美智光电IPO被终止:年营收9.26亿 何享健为实控人
Getting started with JDBC
关于大龄读博的几点回答?
3-全局异常处理
【暑期每日一题】洛谷 P6336 [COCI2007-2008#2] BIJELE
2-统一返回类DTO对象
强连通分量
mysql 单表最多能存多少数据?
CDC source can quit after reading MySQL snapshot split
蓝桥杯A组选数异或
stm32 操作W25Q256 W25Q16 spi flash
Segger's hardware anomaly analysis
QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
计算程序运行时间 demo
[daily question in summer] Luogu p6408 [coci2008-2009 3] pet
[100 cases of unity practice] the single choice multiple choice judgment questions of unity universal question answering system are all common