UVA Solution 357 - Let Me Count The Ways - Solution in C, C++ | Volume 3 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Friday, May 5, 2017

UVA Solution 357 - Let Me Count The Ways - Solution in C, C++ | Volume 3

UVA Solution 357 - Let Me Count The Ways - Solution in C, C++ | Volume 3


UVA Online Judge Solution 357 - Let Me Count The Ways | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=293

Problem Name: 357 - Let Me Count The Ways
Problem Number : UVA - 357 - Let Me Count The Ways
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 357 - Let Me Count The Ways - Solution in C, C++ | Volume 3



UVA Solution 357 - Let Me Count The Ways Code in C, CPP:


#include <stdio.h>

int main() {
    long long DP[30001] = {};
    int m[] = {1, 5, 10, 25, 50}, i, j;
    DP[0] = 1;
    for(i = 0; i < 5; i++) {
        for(j =  m[i]; j <= 30000; j++) {
            DP[j] += DP[j-m[i]];
        }
    }
    while(scanf("%d", &i) == 1) {
        if(DP[i] != 1)
            printf("There are %lld ways to produce %d cents change.\n", DP[i], i);
        else
            printf("There is only 1 way to produce %d cents change.\n", i);
    }
    return 0;
}

No comments:

Post a Comment