Hangzhou Electric oj--1248 Coin Exchange problem (female function answer) __ function

Source: Internet
Author: User
Coin Exchange Issues
Problem Description in a country only 1 points, 2 points, 3 cent coins, the exchange of money n into coins there are many kinds of laws. Please compile the procedure to calculate the total number of different methods.
Input has only one positive integer n,n less than 32768 per line.
Output corresponds to each input and the number of redemption methods.
Sample Input
2934 12553
Sample Output
718831 13137761
Author Smallbeer (CML)
Source Hangzhou Electric ACM Training Team Training Tournament (VII)
Recommend LCY This is a typical application of the female function problem, the direct use of the parent function template can be solved, not with how much technical content. For detailed answers to the parent functions, please click here. http://blog.csdn.net/lishuhuakai/article/details/8044431 Direct Hair Code:
/*
//Typical poor lifting method
#include <iostream>
using namespace std;

int main ()
{
	int x,y,z,n;
	int num;
	while (Cin>>num && num>0)
	{
		n=0;
		for (x=0;x<=num;x++) for (
			y=0;y<=num/2;y++) for (
				z=0;z<=num/3;z++)
					if (x+2*y+3*z==num)
						n++;
		cout<<n<<endl;
	}
	return 0;
}
*
///above the poor lifting method is too slow, my computer ran a full 30 seconds to answer, pit ah.
//Apply the parent function template
#include <iostream>
using namespace std;
const int max=32768;
int c1[max+1],c2[max+1];

int main ()
{
	int n,j,i,k,num;
	for (i=0;i<=max;i++)
	{
		c1[i]=1;c2[i]=0;
	}

	for (i=2;i<=3;i++)
	{for
		(j=0;j<=max;j++) for (
		k=0;k+j<=max;k=k+i)
		{
			c2[j+k]+= C1[J];
		}
		for (j=0;j<=max;j++)
		{
			c1[j]=c2[j];
			c2[j]=0;
		}
		
	}
	while (scanf ("%d", &num)!=eof)
	{
		printf ("%d\n", C1[num]);
	}
	return 0;
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.