标签:flat std cin core ace cout int pac pre
P2871 手链Charm Bracelet
#include<iostream>
#include<cstdio>
using namespace std;
#define tcl(a,b,c) for(a=b;a<=c;a++)
#define etc(a,b,c) for(a=b;a>=c;a--)
const int maxx=100001;
int w[maxx],v[maxx],f[maxx];
int main()
{
int n,m,i,j;
cin>>n>>m;
tcl(i,1,n)
{
cin>>w[i]>>v[i];
}
tcl(i,1,n)
{
etc(j,m,w[i])
{
if(f[j-w[i]]+v[i]>f[j])
f[j]=f[j-w[i]]+v[i]; //01背包核心
}
}
cout<<f[m]<<endl;
return 0;
}
P2722 总分 Score Inflation
#include<iostream>
#include<cstdio>
using namespace std;
#define tcl(a,b,c) for(a=b;a<=c;a++)
#define etc(a,b,c) for(a=b;a>=c;a--)
const int maxx=100001;
int w[maxx],v[maxx],f[maxx];
int main()
{
int n,m,i,j;
cin>>m>>n;
tcl(i,1,n)
{
cin>>v[i]>>w[i];
}
tcl(i,1,n)
{
tcl(j,w[i],m)
{
if(f[j-w[i]]+v[i]>f[j])
f[j]=f[j-w[i]]+v[i];
}
}
cout<<f[m]<<endl;
return 0;
}
水啊
标签:flat std cin core ace cout int pac pre
原文地址:https://www.cnblogs.com/LSWorld/p/bp.html