mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-31 23:41:41 +00:00
Compare commits
4 Commits
5e23f17133
...
b4e809156f
Author | SHA1 | Date | |
---|---|---|---|
b4e809156f | |||
8894e59851 | |||
a026979a58 | |||
db685782e1 |
55
src/8/30/P1063.cpp
Normal file
55
src/8/30/P1063.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
|
||||
dp[i][j]=将[1,j]合并为一堆时的最大总能量
|
||||
dp[i][j]=max(
|
||||
dp[i][j],
|
||||
dp[i][k]+dp[k+1][j]+i.m*k.n*j.n
|
||||
)
|
||||
|
||||
dp[i][j]=0
|
||||
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using ll = int64_t;
|
||||
|
||||
#define pvp(v)do{\
|
||||
std::cout<<#v<<":\n";\
|
||||
for(const auto&i:(v)){\
|
||||
std::cout<<i.first<<", "<<i.second<<"\n";\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
int main(){
|
||||
ll n;
|
||||
std::cin>>n;
|
||||
std::vector<ll> h(2*n+1);
|
||||
std::vector<std::vector<ll>> dp(2*n+1,std::vector<ll>(2*n+1));
|
||||
|
||||
for(ll i=1;i<=n;++i){
|
||||
std::cin>>h[i];
|
||||
h[n+i]=h[i];
|
||||
}
|
||||
// pvp(v);
|
||||
for(ll len=2;len<=n;++len){
|
||||
for(ll i=1;i<=2*n-len;++i){
|
||||
ll j=i+len-1;
|
||||
for(ll k=i;k<j;k++){
|
||||
dp[i][j]=std::max(
|
||||
dp[i][j],
|
||||
dp[i][k]+dp[k+1][j]+h[i]*h[k+1]*h[j+1]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ll ans=0;
|
||||
for(ll i=1;i<=n;i++){
|
||||
ans=std::max(
|
||||
ans,
|
||||
dp[i][i+n-1]
|
||||
);
|
||||
}
|
||||
std::cout<<ans<<"\n";
|
||||
}
|
55
src/8/30/P2016.cpp
Normal file
55
src/8/30/P2016.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
|
||||
|
||||
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
using ll = int64_t;
|
||||
|
||||
ll n;
|
||||
std::vector<std::vector<ll>> edg,dp;
|
||||
|
||||
static inline void dfs(ll f,ll u){
|
||||
for(ll v:edg[u]){
|
||||
if(v==f)continue;
|
||||
dfs(u,v);
|
||||
dp[u][1]+=std::min(
|
||||
dp[v][0],
|
||||
dp[v][1]
|
||||
);
|
||||
dp[u][0]+=dp[v][1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin>>n;
|
||||
edg.resize(n);
|
||||
dp.resize(n,std::vector<ll>(2,0));
|
||||
for(ll i=1;i<=n;++i){
|
||||
dp[i-1][1]=1;
|
||||
ll u,k;
|
||||
std::cin>>u>>k;
|
||||
for(ll j=1;j<=k;++j){
|
||||
ll v;
|
||||
std::cin>>v;
|
||||
edg[u].push_back(v);
|
||||
edg[v].push_back(u);
|
||||
}
|
||||
}
|
||||
|
||||
dfs(0, 0);
|
||||
// for(ll i=0;i<n;i++){
|
||||
// for(ll j=0;j<2;j++){
|
||||
// printf("dp[%lld][%lld]=%lld\n",i,j,dp[i][j]);
|
||||
// }
|
||||
// }
|
||||
std::cout<<std::min(dp[0][0],dp[0][1])<<"\n";
|
||||
}
|
Loading…
Reference in New Issue
Block a user