This commit is contained in:
Zengtudor 2024-08-17 08:10:50 +08:00
parent 17a7d83060
commit 93b63ecdda
3 changed files with 73 additions and 1 deletions

36
day13/P1156/P1156.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <algorithm>
#include <climits>
#include <ios>
#include <iostream>
using namespace std;
const int MAX_T = 1000+5,MAX_FH=30+5,MAX_G=100+5;
int D,G;
struct Rubbish{
int T,F,H;
}rub[MAX_G];
int dp[MAX_G];
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
dp[0]=10;
cin>>D>>G;
for(int i=1;i<=G;i++){
cin>>rub[i].T>>rub[i].F>>rub[i].H;
}
sort(rub+1,rub+1+G,[](Rubbish a,Rubbish b)->bool{
return a.T<b.T;
});
for(int i=1;i<=G;i++){
for(int j=D;j>=0;j--){
if(rub[i].T>dp[j])continue;
if(j+rub[i].H>=D){
cout<<rub[i].T<<endl;
return 0;
}
dp[j+rub[i].H] = max(dp[j],dp[j+rub[i].H]);
dp[j]=dp[j]+rub[i].F;
}
}
cout<<dp[0]<<endl;
}

28
day13/P5662/P5662.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <algorithm>
#include <iostream>
using namespace std;
const int MAX_T=105,MAX_N=105,MAX_M=1e4+5;
int T,N,M;
int p[MAX_T][MAX_N];
int dp[MAX_M];
#define MEM(a,s,n){for(int i=1;i<=s;i++)a[i]=n;}
int main(){
cin>>T>>N>>M;
for(int i=1;i<=T;i++){
for(int j=1;j<=N;j++){
cin>>p[i][j];
}
}
for(int i=1;i<T;i++){
MEM(dp,MAX_M-1,0);
for(int j=1;j<=N;j++){
for(int k=p[i][j];k<=M;k++){
dp[k]=max(dp[k],dp[k-p[i][j]]+p[i+1][j]-p[i][j]);
}
}
M+=dp[M];
}
cout<<M<<endl;
}

View File

@ -169,4 +169,12 @@ target("P1049")
target("P1507")
set_rundir("day13/P1507")
add_files("day13/P1507/P1507.cpp")
add_files("day13/P1507/P1507.cpp")
target("P1156")
set_rundir("day13/P1156")
add_files("day13/P1156/P1156.cpp")
target("P5662")
set_rundir("day13/P5662")
add_files("day13/P5662/P5662.cpp")