当前位置:网站首页>I - Dollar Dayz
I - Dollar Dayz
2022-06-26 13:08: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
The general meaning of the topic is : use n Money to buy value 1~k The items , Items can be purchased repeatedly , How many combinations are there at most
The recursive formula 1.i>=j dp[I][j]=dp[I][j-1]+dp[I-j][j]
2.i<j dp[I][j]=dp[I][I]
Because the result is relatively large So use two ll The array stores the results
One problem that hasn't been solved is the final output If the low order is lower than 17 position , The high position is not equal to 0, This output is obviously wrong , Please answer me
#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]);
}
}
边栏推荐
- Processing function translate (mousex, mousey) learning
- 心脏滴血漏洞(CVE-2014-0160)分析与防护
- Common creation and usage of singletons
- 体现技术深度(无法速成)
- G - Cow Bowling
- How does easygbs solve the abnormal use of intercom function?
- Goto statement to realize shutdown applet
- 【网络是怎么连接的】第二章(下):一个网络包的接收
- Openlayers drawing dynamic migration lines and curves
- RSS rendering of solo blog system failed
猜你喜欢

外观模式(Facade)
RSS rendering of solo blog system failed

Verilog中的系统任务(显示/打印类)--$display, $write,$strobe,$monitor

National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair

Group counting practice experiment 9 -- using cmstudio to design microprogram instructions based on segment model machine (2)

倍福EtherCAT Xml描述文件更新和下载

Explain C language 10 in detail (C language series)

processing 函数translate(mouseX, mouseY)学习

橋接模式(Bridge)

The El form item contains two inputs. Verify the two inputs
随机推荐
[BSidesCF 2019]Kookie 1
UVa11582 [快速幂]Colossal Fibonacci Numbers!
Lightflow completed the compatibility certification with "daocloud Enterprise Cloud native application cloud platform"
微信小程序测试点总结
Electron official docs series: Contributing
Electron official docs series: Examples
IDC报告:百度智能云AI Cloud市场份额连续六次第一
倍福PLC选型--如何看电机是多圈绝对值还是单圈绝对值编码器
D - 滑雪
LeetCode_栈_中等_150. 逆波兰表达式求值
First knowledge - Software Testing
别乱用 FULL_CASE 和 PARALLEL_CASE
Photoshop 2022 23.4.1增加了哪些功能?有知道的吗
【shell】生成指定日期之间的字符串
体现技术深度(无法速成)
Processing polyhedron change
find及du -sh显示权限不够的解决方法
map 取值
[geek challenge 2019] rce me 1
Typescript