This commit is contained in:
Zengtudor 2024-08-16 17:02:48 +08:00
parent fee4e50f03
commit b0c9fe405a
3 changed files with 54 additions and 6 deletions

View File

@ -5,7 +5,7 @@ using namespace std;
const int MAX_N=10000+5;
int sh,sm,eh,em,W,n;
int w[MAX_N],v[MAX_N],c[MAX_N];
int dp[MAX_N][MAX_N];
int dp[MAX_N];
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
@ -22,15 +22,15 @@ int main(){
for(int i=1;i<=n;i++){
if(c[i]==0){
for(int j=w[i];j<=W;j++){
dp[i][j]=max(dp[i-1][j],dp[i][j-w[i]]+v[i]);
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}else{
for(int j=1;j<=c[i];j++){
for(int j=W;j>=w[i];j--){
for(int k=1;k*w[i]<=j&&k<=c[i];k++){
dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]*k]+v[i]*k);
dp[j]=max(dp[j],dp[j-k*w[i]]+v[i]*k);
}
}
}
}
cout<<dp[n][W]<<endl;
cout<<dp[W]<<endl;
}

44
day13/P1855/P1855.cpp Normal file
View File

@ -0,0 +1,44 @@
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <ostream>
using namespace std;
const int MAX = 200+5;
int n,M,T;
int m[MAX],t[MAX];
int readint();
int dp[MAX][MAX];
int main(){
n=readint(),M=readint(),T=readint();
for(int i=1;i<=n;i++){
m[i]=readint(),t[i]=readint();
}
for(int i=1;i<=n;i++){
for(int j=M;j>=1;j--){
for(int k=T;k>=1;k--){
dp[j][k] = dp[j][k];
if(j>=m[i]&&k>=t[i]){
dp[j][k] = max(dp[j][k],dp[j-m[i]][k-t[i]]+1);
}
}
}
}
cout<<dp[M][T]<<endl;
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}

View File

@ -157,4 +157,8 @@ target("P1616")
target("P1833")
set_rundir("day13/P1833")
add_files("day13/P1833/*.cpp")
add_files("day13/P1833/*.cpp")
target("P1855")
set_rundir("day13/P1855")
add_files("day13/P1855/*.cpp")