ways to score n from 3 5 10
Idea is to find ways to get n from only 3
then 5 by using no. of ways by 3 , similar for 10
Code:
public static int ways(int n)
{
int table[]=new int[n+1];
table[0]=1;
int i;
for (i=3; i<=n; i++)
table[i] += table[i-3];
for (i=5; i<=n; i++)
table[i] += table[i-5];
for (i=10; i<=n; i++)
table[i] += table[i-10];
return table[n];
}
then 5 by using no. of ways by 3 , similar for 10
Code:
public static int ways(int n)
{
int table[]=new int[n+1];
table[0]=1;
int i;
for (i=3; i<=n; i++)
table[i] += table[i-3];
for (i=5; i<=n; i++)
table[i] += table[i-5];
for (i=10; i<=n; i++)
table[i] += table[i-10];
return table[n];
}
0 Comments:
Post a Comment