spider68

Combination Sum IV (hw mny combinz is psible for given sum)

Mar 29th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int combinationSum4(vector<int>& nums, int n) {
  4.         int i,j;
  5.         vector<unsigned long long int>a(n+1);
  6.         //memset(a,0,sizeof(a));
  7.         a[0]=1;
  8.         for(i=1;i<=n;i++)
  9.         {
  10.             for(j=0;j<nums.size();j++)
  11.             {
  12.                 if(nums[j]<=i)
  13.                 {
  14.                     a[i]+=a[i-nums[j]];
  15.                 }
  16.             }
  17.         }
  18.         return a[n];
  19.     }
  20. };
Add Comment
Please, Sign In to add comment