HDUOJ----Coin Change
Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10590 Accepted Submission(s): 3535
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
思路: 此题可以采取dfs,但是用分治法还是可以的,优化一下可以达到15ms......
在此贴出代码:
#include<iostream>
using namespace std;
int main()
{
int n,count;
int j,k,m,g,l;
while(cin>>n)
{
count=;
for( j=;j<=n/;j++) //
{
k=m=g=l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break; for( k=;k<=n/;k++) //
{
m=g=l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
for( m=;m<=n/;m++) //
{
g=l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
for( g=;g<=n/;g++) //
{
l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
for( l=;l<=-j-k-m-g;l++) //
{
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
}
}
}
}
} cout<<count<<endl;
}
return ;
}
HDUOJ----Coin Change的更多相关文章
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2069 Coin Change
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- UVA 674 Coin Change(dp)
UVA 674 Coin Change 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...
- JSU省赛队员选拔赛个人赛1(Coin Change、Fibbonacci Number、Max Num、单词数、无限的路、叠筐)
JSU省赛队员选拔赛个人赛1 一.题目概述: A.Coin Change(暴力求解.动态规划) B.Fibbonacci Number(递推求解) C.Max Num(排序.比较) D.单词数 ...
- C - Coin Change (III)(多重背包 二进制优化)
C - Coin Change (III) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- Coin Change (IV) (dfs)
Coin Change (IV) Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu [Subm ...
- Coin Change (II)(完全背包)
Coin Change (II) Time Limit: 1000MS Mem ...
- [LeetCode] Coin Change 2 硬币找零之二
You are given coins of different denominations and a total amount of money. Write a function to comp ...
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
随机推荐
- 构建配置 Enable multidex
官方文档 配置方法数超过 64K 的应用 随着 Android 平台的持续成长,Android 应用的大小也在增加.当您的应用及其引用的库达到特定大小时,您会遇到构建错误,指明您的应用已达到 Andr ...
- RV LayoutManager 流式布局 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- mybatis xml mapper 文件中 if-else 写法
mybaits 中没有else要用chose when otherwise 代替 范例一 <!--批量插入用户--> <insert id="insertBusinessU ...
- C# 将 Json 解析成 DateTable
#region 将 Json 解析成 DateTable /// /// 将 Json 解析成 DateTable. /// Json 数据格式如: /// {table:[{column1:1,co ...
- 简单使用Google Analytics监控网站浏览行为
之前对网页做用户转化率调查这块,找到了谷歌GA事件,现在有时间对使用方法和遇到问题做个简单记录.官方文档其实也介绍的比较清楚,可以查看官方文档. 首先,在官网申请UA-id,然后在主页加入如下代码: ...
- Win32进程创建、进程快照、进程终止用例
进程创建: 1 #include <windows.h> #include <stdio.h> int main() { // 创建打开系统自带记事本进程 STARTUPINF ...
- Java反编译代码分析(一)
浅析如何读懂这种反编译过来的文件,不喜勿喷. 赋值 Node node; Node node1 = _$3.getChildNodes().item(0); node1; node1; JVM INS ...
- hdu 3665Seaside(简单floyd)
Seaside Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- Windows 增强版任务管理器-Process Explorer
百度百科PROCESS EXPLORER介绍 由Sysinternals开发的Windows系统和应用程序监视工具,目前已并入微软旗下.不仅结合了Filemon(文件监视器)和Regmon(注册表监视 ...
- [Functional Programming] Using JS, FP approach with Arrow or State Monad
Using Naive JS: const {modify, get} = require('crocks/State'); const K = require('crocks/combinators ...