This commit is contained in:
Zengtudor 2024-08-17 11:20:38 +08:00
parent 93b63ecdda
commit 8561d633fc
5 changed files with 82 additions and 10 deletions

View File

@ -1,10 +1,29 @@
//AC
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
const int MAX_N=30+5;
const int MAX_V=2e4+5;
int V,n;
int w[MAX_N];
int dp[MAX_V];
int readint();
int main(){
V=readint(),n=readint();
for(int i=1;i<=n;i++){
w[i]=readint();
}
for(int i=1;i<=n;i++){
for(int j=V;j>=w[i];j--){
dp[j]=max(dp[j],dp[j-w[i]]+w[i]);
}
}
cout<<V-dp[V]<<endl;
}
int readint(){

32
day14/P4141/P4141.cpp Normal file
View File

@ -0,0 +1,32 @@
//AC
#include <ios>
#include <iostream>
using namespace std;
const int MAX_N=2e3+5;
int n,m;
int w[MAX_N];
int dp[MAX_N],g[MAX_N];
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>w[i];
}
dp[0]=1;//背包容量为0也是一种选择方案
for(int i=1;i<=n;i++){
for(int j=m;j>=w[i];j--){
dp[j]=(dp[j]+dp[j-w[i]])%10;
}
}
for(int i=1;i<=n;i++){
g[0]=1;//背包容量为0也是一种选择方案
for(int j=1;j<=m;j++){
if(j<w[i])g[j]=dp[j]%10;
else g[j]=(dp[j]-g[j-w[i]]+10)%10;//不使用物品i把j容量填满的方案数 = 把j容量填满的方案总数 - (假设使用i个物品时的方案数=容量为j-w[i]时不使用i个物品的总数)
cout<<g[j];
}
cout<<endl;
}
}

19
day14/P6567/P6567.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <ios>
#include <iostream>
using namespace std;
const int MAX_N = 200+5,MAX_M=1e5+5;
int n,m;
int k[MAX_N],a[MAX_N],t[MAX_M];
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>k[i]>>a[i];
}
for(int i=1;i<=m;i++){
cin>>t[i];
}
}

View File

@ -1,13 +1,7 @@
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
set<int>s;
s.insert(2);
s.insert(3);
auto it = s.lower_bound(2);
cout<<(*(--it))<<endl;
cout<<(*(++it))<<endl;
cout<<(*(--it))<<endl;
cout<<(*(--it))<<endl;
cout<<-INFINITY<<endl;
}

View File

@ -177,4 +177,12 @@ target("P1156")
target("P5662")
set_rundir("day13/P5662")
add_files("day13/P5662/P5662.cpp")
add_files("day13/P5662/P5662.cpp")
target("P4141")
set_rundir("day14/P4141")
add_files("day14/P4141/P4141.cpp")
target("P6567")
set_rundir("day14/P6567")
add_files("day14/P6567/P6567.cpp")