最近几天有点忙(我正在出洛谷月赛)好久没发题解了,就拿一道水体开开胃吧!
这道题也是非常简单,话不多说,我们直截了当上代码:
n,m=[int(x) for x in input().split()]
a=[]
while not len(a)>=n:
t=[int(x) for x in input().split()]
a.extend(t)
a.insert(0,0)
f=[[0 for i in range(m+2)] for j in range(n+2)]
for i in range(1,n+1):
for j in range(1,m+1):
if j==a[i]:
f[i][j]=f[i-1][j]+1
elif j>a[i]:
f[i][j]=f[i-1][j]+f[i-1][j-a[i]]
else:
f[i][j]=f[i-1][j]
print(f[n][m])
完美结束,100分!