Reach a given score | Practice | GeeksforGeeks

Consider a game where a player can score 3 or 5 or 10 points in a move. Given a total score n, find number of distinct combinations to reach the given score.
Example:
Input
3
8
20
13
Output
1
4
2
Explanation
For 1st example when n = 8
{ 3, 5 } and {5, 3} are the 
two possible permutations but 
these represent the same 
cobmination. Hence output is 1.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function count( ) which takes N as input parameter and returns the answer to the problem.
Constraints:
1 ≤ T ≤ 100
1 ≤ n ≤ 1000
0
milindprajapatmst192 weeks ago
# define ll long long

ll count(ll n) {
    vector<ll> dp(n + 1, 0);
	dp[0] = 1;
	for (int i = 3; i <= n; i++)
	    dp[i] += dp[i - 3];
	for (int i = 5; i <= n; i++)
	    dp[i] += dp[i - 5];
	for (int i = 10; i <= n; i++)
	    dp[i] += dp[i - 10];
    return dp[n];
}
0
vikassaraimeer19991 month ago
very easy c++ solution
long long int count(long long int n)
{
	long long int table[n+1],i;
	memset(table, 0, sizeof(table));
	table[0]=1;                 // If 0 sum is required number of ways is 1.
	
	// Your code here
	for(int i=3;i<=n;i++){
	    table[i]+=table[i-3];
	}
		for(int i=5;i<=n;i++){
	    table[i]+=table[i-5];
	}
		for(int i=10;i<=n;i++){
	    table[i]+=table[i-10];
	}
	
	return table[n];
}
 
0
cs19b01911 month ago
long long int count(long long int n){int count = 0;int n1 = n/10;for(int i=0;i<=n1;i++){    int temp = (n - i*10)/5;    for(int j=0;j<=temp;j++)    {        int temp1 = n - i*10 - j*5;        if(temp1 % 3 == 0)         count++;    }}return count;}
0
ssshrivastava2
This comment was deleted.
+2
dugguanshuman2 months ago
Top down approach DP:
int dp[1001][3];
int arr[3]={3, 5, 10};
int long long util(int long long n, int x){
    if(n==0){
        return 1;
    }
    else if(n<0){
        return 0;
    }
    if(dp[n][x]!=-1){
        return dp[n][x];
    }
    int ans=0;
    for(int i=x; i<3; i++){
        ans+=util(n-arr[i], i);
    }
    return dp[n][x]=ans;
}
long long int count(long long int n){
    memset(dp, -1, sizeof(dp));
	return util(n, 0);
}
+14
manishpritmani063 months ago
👈Do upvote if you liked my solution. 👍
Tau 🥸 Samazh na aaye toh LinkedIn me aajao..
Linkedin/manish-pritmani
long long int count(long long int n) {
	long long int table[n+1],i;
	memset(table, 0, sizeof(table));
	table[0]=1;    
	
	for(int i=3;i<=n;i++)
        table[i]+=table[i-3];
    for(int i=5;i<=n;i++)
        table[i]+=table[i-5];
    for(int i=10;i<=n;i++)
        table[i]+=table[i-10];

	return table[n];
}
0
raunakmishra12433 months ago
long long	int A[3]={3,5,10};
	 long long int t[4][n+1];
	 for(int i=0;i<=3;i++)
	 {
	     for(int j=0;j<=n;j++)
	     {
	     if(j==0)
	     t[i][j]=1; 
	     if(i==0 && j!=0)
	     t[i][j]=0;
	     
	     }
	     
	 }
	for(int i=1;i<=3;i++)
	{
	    
	    for(int j=1;j<=n;j++)
	    {
	        
	        if(A[i-1]<=j)
	        t[i][j]=t[i][j-A[i-1]]+t[i-1][j];
	        else
	        t[i][j]=t[i-1][j];
	        
	        
	        
	    }
	    
	}
	
	// Your code here
	
	return t[3][n];
0
raunakmishra1243
This comment was deleted.
+1
chetanvegad073 months ago
def count(n):   #your code here   return help(n,0,0)   def help(n,a,b):   if(n < 0):       return 0
   if(n == 0):       return 1      x,y,z=0,0,0   if(a==0):       x=help(n-3,a,b)   a = 1
   if(b==0):       y=help(n-5,a,b)      b = 1   z=help(n-10,a,b)      return x+y+z
 
-2
pratikpatil56113 months ago
Same as unbounded knapsack
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.