当前位置:网站首页>I - Dollar Dayz
I - Dollar Dayz
2022-06-26 12:40:00 【YJEthan】
Description
1 @ US$3 + 1 @ US$2 1 @ US$3 + 2 @ US$1 1 @ US$2 + 3 @ US$1 2 @ US$2 + 1 @ US$1 5 @ US$1Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100).
Input
Output
Sample Input
5 3
Sample Output
5
题目的大致意思是:用n钱去买价值1~k的物品,物品可重复购买,请问最多有多少种购买的组合方式
递推公式1.i>=j dp[I][j]=dp[I][j-1]+dp[I-j][j]
2.i<j dp[I][j]=dp[I][I]
由于结果比较大 故用两个ll数组存放结果
有个问题一直没解决就是最后输出的时候 如果低位低于17位,而高位不等于0,这种输出显然是不对的,求大佬解答
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define ll long long
ll a[10009][108],b[10009][106];
ll inf;
int main()
{
int n,m,i,j;
inf=1;
for(i=1;i<=18;i++)
{
inf=inf*10;
}
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=1;i<=m+1;i++)
{
a[0][i]=1;
}
for(i=1;i<=n+1;i++)
{
a[i][1]=1;
}
for(i=1;i<=m+1;i++)
{
a[1][i]=1;
}
for(i=2;i<=n;i++)
{
for(j=2;j<=m;j++)
{
if(i<j)
{
a[i][j]=a[i][i];
b[i][j]=b[i][i];
}
else
{
a[i][j]=(a[i][j-1]+a[i-j][j])%inf;
b[i][j]=b[i][j-1]+b[i-j][j]+(a[i][j-1]+a[i-j][j])/inf;
}//printf("%d ",a[i][j]);
}
}
if(b[n][m]!=0)
printf("%lld",b[n][m]);
printf("%lld\n",a[n][m]);
}
}
边栏推荐
- Adobe Acrobat prevents 30 security software from viewing PDF files or there are security risks
- el-form-item 包含两个input, 校验这两个input
- C# const详解:C#常量的定义和使用
- [esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3
- Summary of some application research cases of UAV Remote Sensing in forest monitoring
- 【Spark】.scala文件在IDEA中几种图标的解释
- Redis learning - 05 node JS client operation redis and pipeline pipeline
- processing 随机生成线动画
- 国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
- Software testing - Fundamentals
猜你喜欢

黑马笔记---常用API

power designer - 自定义注释按钮

倍福PLC实现绝对值编码器原点断电保持---bias的使用

Software testing - concept

Lightflow completed the compatibility certification with "daocloud Enterprise Cloud native application cloud platform"

Openlayers drawing dynamic migration lines and curves

goto语句实现关机小程序

计组实践实验9——使用CMStudio设计基于分段模型机微程序指令(2)

别乱用 FULL_CASE 和 PARALLEL_CASE

Websocket and socket IO case practice
随机推荐
Openlayers drawing dynamic migration lines and curves
心脏滴血漏洞(CVE-2014-0160)分析与防护
Unit practice experiment 8 - using cmstudio to design microprogram instructions based on basic model machine (1)
小白懒人专用-win10-win11一键安装版
Deeply analyze the differences between dangbei box B3, Tencent Aurora 5S and Xiaomi box 4S
Learning Processing Zoog
Software testing - Fundamentals
倍福PLC基于CX5130实现数据的断电保持
倍福Ethercat模块网络诊断和硬件排查的基本方法
倍福EtherCAT Xml描述文件更新和下载
使用SSH密钥对登陆服务器
自定义封装下拉组件
初识-软件测试
LeetCode_栈_中等_150. 逆波兰表达式求值
How does easygbs solve the abnormal use of intercom function?
P2393 yyy loves Maths II
轻流完成与「DaoCloud Enterprise 云原生应用云平台」兼容性认证
This function has none of deterministic, no SQL solution
Word文档导出(使用固定模板)
Processsing 鼠标交互 学习