Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
147900 林泽豪 收服精灵 C++ 通过 100 0 MS 344 KB 601 2024-05-20 13:35:55

Tests(5/5):


#include<bits/stdc++.h> using namespace std; const int N=1002; int f[N][N], j[N],h[N],C,R=N; int main(){ int n,m,k; cin>>n>>m>>k; f[0][0]=1; for(int i=1;i<=k;i++)cin>>j[i]>>h[i]; for(int i=1;i<=k;i++){ for(int l=m;l>=h[i]+1;l--){ for(int p=n;p>=j[i];p--){ f[p][l]=max(f[p][l],f[p-j[i]][l-h[i]]+1); } } } /* for(int i=1;i<=n;i++){ for(int l=1;l<=m;l++)cout<<f[i][l]<<' ';cout<<endl; }*/ C=f[n][m]; for(int i=1;i<=n;i++){ for(int l=1;l<=m;l++){ if(C==f[i][l]){ R=min(R,l); } } } cout<<C<<" "<<m-R+1; }


测评信息: