P1164
#include<bits/stdc++.h>
#define int long long
#define F(x,y,z) for(int i=x;i<=y;i+=z)
using namespace std;
int n,m,ans;
int a[101],f[101][10001];
void dg(int dep,int money)
{
while(dep<=n){
f[dep][money]+=f[dep-1][money];
if(money>=a[dep]){
f[dep][money]+=f[dep-1][money-a[dep]];
}
money--;
if(money<=0){
money=m;dep++;
}
}
}
void reads(){
cin>>n>>m;
return;
}
int red(int x){
cin>>a[x];
return 0;
}
void like(){
cout<<f[n][m];
return;
}
signed main()
{
ios::sync_with_stdio(false);cin.tie();cout.tie();
reads();
F(1,n,1)
{
red(i);
}
for(int i=0;i<=n;i++){
f[i][0]=1;
}
dg(1,m);
like();
return 0;
}
P1616
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long m,n,w[1e7],c[1e7],i,v,f[1e7][1e7];
cin>>m>>n;
for(i=1;i<=n;i++)cin>>w[i]>>c[i];
for(i=1;i<=n;i++)
for(v=1;v<=m;v++)
if(v<w[i])f[i][v]=f[i-1][v];
else if(f[i-1][v]>f[i][v-w[i]]+c[i])f[i][v]=f[i-1][v];
else f[i][v]=f[i][v-w[i]]+c[i];
cout<<f[n][m];return 0;
}