Tips for solving problems:
(Frog jump Step: There are N-step, frogs can jump one step at a time can also jump two-step, ask how good the total number of Jump method)
1, before the idea of this problem was mistaken, thought is a recursive, like a frog jumping steps, with Fibonacci solution. But the Fibonacci will definitely go beyond the scope. In turn thinking of their own thinking is actually wrong. Frog jump step In fact, to distinguish between the order, such as three steps, first jump two and then jump first level and jump two to jump one level is two different methods, but the coin problem two points and a point can be pooled into three cents but not in order.
2, the coin has three algorithms, first said first. The first is full knapsack problem, dynamic programming, one dollar only one method of rounding, all is a dollar, and then planning two yuan, will be two a dollar can be replaced with a single yuan, so you can replace a one-dollar on more than one method, because you can choose replacement or not replacement, and then gradually expand the amount of money can be, ternary ibid.
3, the second algorithm, and the first more similar, but first of the ternary, so first see how many ternary, N/3 kind of not enough directly to fill on the line, n/3+1,+1 part is the whole use of one dollar to constitute the situation. Then is gradually subtract I a ternary with two yuan to replace, the way of thinking with the second, add up on the line
Topic
Coin Exchange Issues
http://acm.hdu.edu.cn/showproblem.php?pid=1284
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3261 accepted Submission (s): 1842
Problem Description in a country with only 1 cents, 2 cents, 3 cents, there are many ways to exchange money n coins. Please write a procedure to figure out how many kinds of methods are in common.
Input is only one positive integer per line n,n less than 32768.
Output corresponds to each input, the number of conversion methods.
Sample Input 2934 12553
Sample Output 718831 13137761
Author Smallbeer (CML)
Source Hangzhou Electronic ACM Team Training Competition (VII)
Method One:
#include <stdio.h>
#include <cstring>
long long num[32770];
int main ()
{
memset (num,0,sizeof (num));
Num[0] = 1;
for (int i=1;i<=3;i++) for
(int j=i;j<=32768;j++)
num[j] + = num[j-i];
int n;
while (~SCANF ("%d", &n))
{
printf ("%lld\n", Num[n]);
}
Method Two:
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int n;
while (~SCANF ("%d", &n))
{
long long sum = 0;
sum = N/3 + 1;
for (int i=0;i<=n/3;i++)
{
int t = (n-i*3)/2;
sum + = t;
}
printf ("%lld\n", sum);
}
Method Three: (Parent function)
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int c1[32770],c2[32770];
int n;
for (int i=0;i<=32768;i++)
{
c1[i] = 1;
C2[i] = 0;
}
for (int i=2;i<=3;i++)
{for
(int j=0;j<=32768;j++)
{for (int
k=0;k+j<=32768;k+=i)
{
C2[k+j] + = c1[j]
;
}
for (int k=0;k<=32768;k++)
{
c1[k] = c2[k];
C2[k] = 0;
}}
while (~SCANF ("%d", &n))
{
printf ("%d\n", C1[n]);
}