并没有超时 然后贪了 第一个性价比最高的
被卡掉。。
```cpp
#include <iostream>
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
const int N=10005,MAXT=100005;
struct things{
int t, v;
double rank;
things(){ }
things(double a,double b):t(a),v(b),rank((double)b/a){ }
bool operator <(const things &b)const{
return rank > b.rank;
}
}a[N];
int T,M;
int dp[MAXT],mint=0x7fffffff;
inline int read(){
char ch;int x=0;
while (!isdigit(ch=getchar()));
for(;isdigit(ch);x=(x<<3)+(x<<1)+ch-'0', ch=getchar());
return x;
}
int main(){
cin>>T>>M;
int t,v;
for(int i=1;i <= M;i++)
t=read(),v=read(),mint=min(mint,t),
a[i]=things(t,v);
sort(a+1,a+M+1);
// t[i]=read(),v[i]=read();
// scanf("%d%d",&t[i],&v[i]);
int res=T,k,ans;
for(k=1;k*a[1].t <= T;k++); k--;
ans=k*a[1].v;
res=T-k*a[1].t;
for(int i=2;i <= M;i++){
if(res < mint) break;
if(res < a[i].t) continue;
for(int k=1; k*a[i].t <= res ;k++){
for(int j=res;j >= k*a[i].t;j--){
if(dp[j] < dp[j-k*a[i].t]+k*a[i].v)
dp[j] = dp[j-k*a[i].t]+k*a[i].v;
}
}
}
cout<<ans+dp[res]<<endl;
return 0;
}
```
by Leaves_Flower @ 2017-11-08 17:05:15
然后这时我才发现完全背包和01 状态转移方程不太一样
by Leaves_Flower @ 2017-11-08 17:07:37