1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| #include <bits/stdc++.h> #include <bits/extc++.h> #define mp make_pair #define rep(x,y,z) for (int x=(y);(x)<=(z);(x)++) #define per(x,y,z) for (int x=(y);(x)>=(z);(x)--) #define lowbit(x) ((x)&(-(x))) #ifdef DEBUG #define debugdo(X) X #define debugndo(X) #define debugout(X) cout<<(#X)<<"="<<(X)<<endl #else #define debugdo(X) #define debugndo(X) X #define debugout(X) #endif const int inf=0x3f3f3f3f; using namespace std; typedef long long LL; typedef pair<int,int> pairs;
template<typename T> inline void read(T &x){char ch;x=0;bool flag=false;ch=getchar();while (ch>'9'||ch<'0') {if (ch=='-') flag=true;ch=getchar();}while ((ch<='9'&&ch>='0')){x=x*10+ch-'0';ch=getchar();}if (flag) x*=-1;} template<typename T,typename U> inline void read(T &x,U &y){read(x);read(y);} template<typename T,typename U,typename V> inline void read(T &x,U &y,V &z){read(x);read(y);read(z);}
const int maxn=1111; int n,m; int f[maxn][maxn]; vector<pairs> a[maxn]; int main() { read(m,n); rep(i,1,n) { int x,y,z; read(x,y,z); a[z].push_back(mp(x,y)); } rep(i,1,1000) { rep(j,0,m) { f[i][j]=f[i-1][j]; for (auto to:a[i]) { if (j<to.first) continue; f[i][j]=max(f[i][j],f[i-1][j-to.first]+to.second); } } } int ans=0; rep(i,0,m) ans=max(ans,f[1000][i]); printf("%d\n",ans); return 0; }
|