From f8a3eb88d8f7b4718bc72546aa8b0a0541848eaa Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Fri, 15 Nov 2024 11:45:10 +0800 Subject: [PATCH] update --- src/U130967/U130967.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/U130967/U130967.cpp diff --git a/src/U130967/U130967.cpp b/src/U130967/U130967.cpp new file mode 100644 index 0000000..f472700 --- /dev/null +++ b/src/U130967/U130967.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +using std::cout, std::cin; + +using int64 = int64_t; +const int64 max_nm = 5e3+5; +int64 n, m, a[max_nm], b[max_nm], hist, dp[max_nm], costs[max_nm][max_nm], inf=std::numeric_limits::max(); + +auto mpow(int64 b, int64 e)->int64{ + if(b==1)return 1; + int64 ret{b}; + for(int64 i{2};i<=e;i++){ + ret*=b; + } + return ret; +} + +int main(){ + cin>>n>>m; + std::fill(dp, dp+1+n, inf); + dp[0]=0; + for(int64 i{1};i<=m;i++){ + cin>>a[i]>>b[i]; + costs[i][1] = a[i]; + for(int64 j{2};j<=n;j++){ + costs[i][j] = a[i]*mpow(j, b[i]); + // cout<=1;j--){ + for(int64 x{1};x<=j;x++){ + if(dp[j-x]!=inf){ + dp[j]=std::min( + dp[j], + dp[j-x]+costs[i][x] + ); + } + } + } + } + cout<