leetcode每日一题-面试题08-11 硬币

在这里插入图片描述
在这里插入图片描述
参考链接

是个动态规划

const int MOD = 1e9+7;
class Solution {
public:
    int waysToChange(int n) {
          vector<long long> dp;
          int val[4] = {25, 10, 5, 1};
          dp.resize(n+1);
          dp[0] = 1;
          for(int x:val)
          {
              for(int i=x;i<=n;i++)            
              {
                  dp[i] = (dp[i]+dp[i-x])%MOD;
              }
          }
          return dp[n];
    }
};
原创文章 39 获赞 5 访问量 4918

猜你喜欢

转载自blog.csdn.net/q1072118803/article/details/105717446
今日推荐