<DFS๋ก ํ ๊ฒฝ์ฐ, ์ํํธ๋ฆฌ>
def DFS(L, s):
global cnt
if s > t: # ์ปท ์ฃ์ง
return
if L == k:
if s == t:
cnt += 1
else:
for i in range(coin[L][1]+1):
DFS(L+1, s+(i*coin[L][0]))
if __name__ == '__main__':
t = int(input()) # ์งํ์ ๊ธ์ก
k = int(input()) # ๋์ ์ ๊ฐ์ง ์
coin = []
for _ in range(k):
coin.append(list(map(int, input().split())))
cnt = 0
DFS(0, 0)
print(cnt)
<DP๋ก ํ๊ธฐ>
t=int(input())
n=int(input())
dy=[0]*(t+1)
dy[0]=1
for i in range(n):
a, b=map(int, input().split())
for j in range(t, 0, -1):
for k in range(1, b+1):
if(j-a*k<0): break
dy[j]+=dy[j-a*k]
print(dy[t])