update
This commit is contained in:
parent
93b63ecdda
commit
8561d633fc
@ -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
32
day14/P4141/P4141.cpp
Normal 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
19
day14/P6567/P6567.cpp
Normal 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];
|
||||
}
|
||||
|
||||
}
|
10
test.cpp
10
test.cpp
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user