357 - Let Me Count The Ways

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

redrumpeace
New poster
Posts: 3
Joined: Fri May 29, 2009 9:20 am

Re: 357 WA

Post by redrumpeace »

Hello, i got WA, i've checked the output and i think its good..
the code is :

Code: Select all

# include <stdio.h>
# include <stdlib.h>
# include <iostream>
using namespace std;

int main ()
{
	int uang;
	long long dp[5][30001];
	int nilai[5] = {1,5,10,25,50};
		
	for (int i = 0; i <= uang; i++)
	{
		dp[0][i] = 1;
	}
		
	for (int i = 1; i < 5; i++)
	{
		for (int j = 0; j <= 30000; j++)
		{
			if (j < nilai[i]) dp[i][j] = dp[i-1][j];
			else
			{
				dp[i][j] = dp[i-1][j] + dp[i][j-nilai[i]];
			}
		}
	}
	
	while (scanf("%d", &uang) == 1)
	{
		if (dp[4][uang] > 1)
		{
			cout << "There are " << dp[4][uang] << " ways to produce " << uang << " cents change.\n";
		}
		else
		{
			cout << "There is only 1 way to produce " << uang << " cents change.\n";
		}
	}
}
Anyone know why i got WA?

Post Reply

Return to “Volume 3 (300-399)”