HDU1398 (a slightly higher number of female functions, to the previous supplement)

Source: Internet
Author: User

Problem descriptionpeople in Silverland use square coins. Not only they has square shapes but also their values is square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e, 1-credit Coins, 4-credit Coins, 9-credit Coins, ..., and 289-credit coins, is available in Silverland.
There is four combinations of coins to pay ten credits:

Ten 1-credit coins,
One 4-credit coin and six 1-credit coins,
4-credit coins and 1-credit coins, and
One 9-credit coin and one 1-credit coin.

Your mission is to count the number of ways to pay a given amount using coins of Silverland.

Inputthe input consists of lines each containing an integer meaning an amount to being paid, followed by a line containing a Zero. You may assume the amounts is positive and less than 300.

Outputfor each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.

Sample Input210300

Sample Output1427
1#include <stdio.h>2 intsave[ the],temp[ the];3 inta[ -];4 intMain ()5 {6     intN;7      for(intI=0; i<= -; i++)8a[i]=i*i;9      while(~SCANF ("%d", &n) &&N)Ten     { One          for(intI=0; i<=n; i++) A         { -save[i]=1; -temp[i]=0; the         } -          for(intI=2; a[i]<=n; i++) -         { -              for(intj=0; j<=n; J + +) +                  for(intk=0; k+j<=n; k+=A[i]) -temp[k+j]+=Save[j]; +              for(intk=0; k<=n; k++) A             { atsave[k]=Temp[k]; -temp[k]=0; -             } -         } -printf"%d\n", Save[n]); -     } in}

Only need to make a few changes, but at the beginning because I hit a a[i] table, and understand that there is a problem with the death cycle of the situation, the future of the blog details (it is too late today, for me)

HDU1398 (a slightly higher number of female functions, to the previous supplement)

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.