day 13 dp
This commit is contained in:
parent
7c01a98c26
commit
b130e643b8
@ -1,4 +1,4 @@
|
||||
//30%Points k==1
|
||||
//60%Points k==1 & 1->k->n
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
#include <cstdlib>
|
||||
@ -21,15 +21,28 @@ int main(){
|
||||
for(int i=1;i<=n;i++){
|
||||
nodes[i].t=readint();
|
||||
}
|
||||
if(k==1){AC_KE_Q1();exit(0);}
|
||||
|
||||
}
|
||||
void AC_KE_Q1(){
|
||||
for(int i=1;i<=m;i++){
|
||||
const int u=readint(),v=readint();
|
||||
nodes[u].next.push_back(v);
|
||||
nodes[v].next.push_back(u);
|
||||
}
|
||||
if(k==1){AC_KE_Q1();exit(0);}
|
||||
int uNum=k-1;
|
||||
cout<<"P";
|
||||
for(int i=2;i<n;i++){
|
||||
if(uNum){
|
||||
uNum--;
|
||||
cout<<"U";
|
||||
}else{
|
||||
cout<<"P";
|
||||
}
|
||||
}
|
||||
cout<<"U"<<endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AC_KE_Q1(){
|
||||
bool isUPrint = false;
|
||||
for(int i=1;i<=n;i++){
|
||||
if (!isUPrint) {
|
||||
|
39
day13/P1616/P1616.cpp
Normal file
39
day13/P1616/P1616.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define int long long
|
||||
|
||||
const int MAX_M=1e4+5;
|
||||
const int MAX_T=1e7+5;
|
||||
int T,m;
|
||||
int t[MAX_M],v[MAX_M];
|
||||
int dp[MAX_T];
|
||||
|
||||
int readint();
|
||||
|
||||
signed main(){
|
||||
T=readint(),m=readint();
|
||||
for(int i=1;i<=m;i++){
|
||||
t[i]=readint();
|
||||
v[i]=readint();
|
||||
}
|
||||
for(int i=1;i<=m;i++){
|
||||
for(int j=t[i];j<=T;j++){
|
||||
dp[j] = max(dp[j],dp[j-t[i]]+v[i]);
|
||||
}
|
||||
}
|
||||
cout<<dp[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;
|
||||
}
|
2
day13/P1616/P1616_10.in
Normal file
2
day13/P1616/P1616_10.in
Normal file
@ -0,0 +1,2 @@
|
||||
10000000 1
|
||||
1 10000
|
1
day13/P1616/P1616_10.out
Normal file
1
day13/P1616/P1616_10.out
Normal file
@ -0,0 +1 @@
|
||||
100000000000
|
41
day13/P2871/P2871.cpp
Normal file
41
day13/P2871/P2871.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
//AC
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int MAX_M = 1'2880+5;
|
||||
int dp[MAX_M],w[MAX_M],v[MAX_M];
|
||||
int n,m;
|
||||
|
||||
int readint();
|
||||
|
||||
int main(){
|
||||
n=readint();
|
||||
m=readint();
|
||||
|
||||
for(int i=1;i<=n;i++){
|
||||
w[i]=readint();
|
||||
v[i]=readint();
|
||||
}
|
||||
|
||||
for(int i=1;i<=n;i++){
|
||||
for(int j=m;j>=w[i];j--){
|
||||
dp[j]=max(dp[j-w[i]]+v[i],dp[j]);
|
||||
}
|
||||
}
|
||||
|
||||
cout<<dp[m]<<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;
|
||||
}
|
BIN
day13/背包DP-基本操作.pdf
Normal file
BIN
day13/背包DP-基本操作.pdf
Normal file
Binary file not shown.
@ -146,3 +146,11 @@ target("U466178")
|
||||
local s = tostring(v)
|
||||
add_tests(s,{files="day12/U466178/U466178.cpp",defines="OITEST",run_timeout=1000,runargs={"ex_circle"..s..".in","ex_circle"..s..".ans"}})
|
||||
end
|
||||
|
||||
target("P2871")
|
||||
set_rundir("day13/P2871")
|
||||
add_files("day13/P2871/*.cpp")
|
||||
|
||||
target("P1616")
|
||||
set_rundir("day13/P1616")
|
||||
add_files("day13/P1616/*.cpp")
|
Loading…
Reference in New Issue
Block a user