!/bin/python -*- coding: utf8 -*- 硬币数目 100% import sys import os import re class Solution: def change(self, amount, coins): # Write Code Here ans = 0 dp = [0] * (amount + 1) for j in coins: for i in range(amount + 1): if i - j == 0: dp[i] += 1 elif i - j > 0: dp[i] += dp[i - j] return dp[-1] _amount = int(input()) _coins_cnt = 0 _coins_cnt = int(input()) _coins_i = 0 _coins = [] while _coins_i < _coins_cnt: _coins_item = int(input()) _coins.append(_coins_item) _coins_i += 1 s = Solution() res = s.change(_amount, _coins) print(str(res) + "\n")
# 针对一组query-item集合,按照字粒度将文本切分后, # 选择query-item***现字数最高的5个item,共现字数相同时, # 选择原始位置更靠前的结果,最后按照item的字母序,打印选择出的item, # 每行为一个item结果。 # 不会 0% query = input() nums = [] item = [[] for _ in range(10)] for i in range(10): item[i] = input() ans = 0 for j in item[i]: for k in query: if j == k: ans += 1 nums.append(ans)
# 连续子数组最大和 100% def search(input_array): # write code here n = len(input_array) dp = [0] * n dp[0] = input_array[0] for i in range(1, n): dp[i] = max(input_array[i], input_array[i]+dp[i-1]) return max(dp)
全部评论
(0) 回帖