day 13 dp

This commit is contained in:
Zengtudor 2024-08-16 10:51:09 +08:00
parent 7c01a98c26
commit b130e643b8
7 changed files with 110 additions and 6 deletions

View File

@ -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
View 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
View File

@ -0,0 +1,2 @@
10000000 1
1 10000

1
day13/P1616/P1616_10.out Normal file
View File

@ -0,0 +1 @@
100000000000

41
day13/P2871/P2871.cpp Normal file
View 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;
}

Binary file not shown.

View File

@ -145,4 +145,12 @@ target("U466178")
for v=1,8 do
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
end
target("P2871")
set_rundir("day13/P2871")
add_files("day13/P2871/*.cpp")
target("P1616")
set_rundir("day13/P1616")
add_files("day13/P1616/*.cpp")