当前位置:网站首页>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]);
}
}
边栏推荐
- Openlayers drawing dynamic migration lines and curves
- 机组实践实验8——使用CMStudio设计基于基本模型机微程序指令(1)
- 心脏滴血漏洞(CVE-2014-0160)分析与防护
- openlayers 绘制动态迁徙线、曲线
- C语言:练习题二
- 文件远程同步、备份神器rsync
- goto语句实现关机小程序
- 【shell】生成指定日期之间的字符串
- Electron official docs series: Best Practices
- NoSQL mongodb - 02 mongodb server installation, mongodb shell, basic concepts and visualization tools
猜你喜欢

Detailed explanation of C const: definition and use of C constant

Deep parsing MySQL binlog

Echart堆叠柱状图:色块之间添加白色间距效果设置
微信小程序测试点总结

倍福TwinCAT3 NCI在NC轴界面中的基本配置和测试

Openlayers drawing dynamic migration lines and curves

National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?

使用SSH密钥对登陆服务器

processing 随机生成线动画

Redis learning - 02 common data types, operation commands and expiration time
随机推荐
Power Designer - Custom Comment button
[esp32-C3][RT-THREAD] 基于ESP32C3运行RT-THREAD bsp最小系统
第十章 设置结构化日志记录(二)
详细讲解C语言11(C语言系列)
[geek challenge 2019] rce me 1
Source code learning: atomicinteger class code internal logic
Adobe Acrobat阻止30款安全软件查看PDF文件 或存在安全风险
Less than 40 lines of code to create a blocprovider
Echart堆叠柱状图:色块之间添加白色间距效果设置
ES6模块
Learning Processing Zoog
Electron official docs series: Best Practices
心脏滴血漏洞(CVE-2014-0160)分析与防护
Electron official docs series: Contributing
软件测试测试常见分类有哪些?
processing 函数translate(mouseX, mouseY)学习
Sharing ideas for a quick switch to an underlying implementation
File remote synchronization and backup artifact Rsync
轻流完成与「DaoCloud Enterprise 云原生应用云平台」兼容性认证
This function has none of deterministic, no SQL solution