2024暑假集训测试28
前言
- 比赛链接。
上午要输液所以没有打,就下午改一改,应该明天就能回去了。
T1 与和
T2 函数
对于
之后直接 DP 转移即可,设
第一维可以滚掉。
点击查看代码
#include<bits/stdc++.h> #define ll long long #define endl '\n' #define sort stable_sort using namespace std; const int N=2e5+10; template<typename Tp> inline void read(Tp&x) { x=0;register bool z=true; register char c=getchar(); for(;c<'0'||c>'9';c=getchar()) if(c=='-') z=0; for(;'0'<=c&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48); x=(z?x:~x+1); } template<typename T,typename ...Tp> inline void read(T &x,Tp &...y){read(x);read(y...);} template<typename Tp> inline void wt(Tp x) {if(x>9)wt(x/10);putchar((x%10)+'0');} template<typename Tp> inline void write(Tp x) {if(x<0)putchar('-'),x=~x+1;wt(x);} template<typename T,typename ...Tp> inline void write(T x,Tp ...y){write(x);putchar(' ');write(y...);} int n,k; ll f[11]; struct aa {int a,b;}e[N]; bool cmp(aa a,aa b) {return a.b*(b.a-1)>b.b*(a.a-1);} signed main() { read(n,k); for(int i=1;i<=n;i++) read(e[i].a,e[i].b); sort(e+1,e+1+n,cmp); f[0]=1; for(int i=1;i<=n;i++) for(int j=min(i,k);j>=1;j--) f[j]=max(f[j],f[j-1]*e[i].a+e[i].b); write(f[k]); }
T3 袋鼠
和某次的 DP 搬运工是同一种题型,预设型 DP。
原问题可以转化为
那么考虑预设型 DP,从小到大插数,设
-
且 :-
新开了一段,因为后面插入的数能接到他两边的一定都比他大,所以一定合法,加入前共有 段所以有 个位置可以放但是若 就不能放开头了,同理 就不能放结尾了,故有: -
接在一段的开头或结尾且并不使两段接壤,因为此时与他相邻的数一定小于他,而后面再加入的与其相邻的数一定大于他,故一定不合法。 -
使两段接壤,因为此时与其相邻的两个数一定都小于他,所以一定合法,在进行这一步前有 个段产生 个间隙,故此有:
-
-
或 :此时他是一定接在开头或结尾的,故最终只有一个数与其相邻,因为之前加入的数都比他小,所以一定合法,同时不存在使两段接壤的情况,只需要考虑新开一段和接在原来段的开头或结尾即可,其所填位置唯一,故有:
最终一定只有一段,故答案为
点击查看代码
#include<bits/stdc++.h> #define ll long long #define endl '\n' #define sort stable_sort using namespace std; const int N=2e3+10,P=1e9+7; template<typename Tp> inline void read(Tp&x) { x=0;register bool z=true; register char c=getchar(); for(;c<'0'||c>'9';c=getchar()) if(c=='-') z=0; for(;'0'<=c&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48); x=(z?x:~x+1); } template<typename T,typename ...Tp> inline void read(T &x,Tp &...y){read(x);read(y...);} template<typename Tp> inline void wt(Tp x) {if(x>9)wt(x/10);putchar((x%10)+'0');} template<typename Tp> inline void write(Tp x) {if(x<0)putchar('-'),x=~x+1;wt(x);} template<typename T,typename ...Tp> inline void write(T x,Tp ...y){write(x);putchar(' ');write(y...);} int n,s,t,f[2][N]; signed main() { read(n,s,t); f[1][1]=1; for(int i=2;i<=n;i++) for(int j=1;j<=i;j++) { if(i!=s&&i!=t) f[i&1][j]=(1ll*f[(i-1)&1][j-1]*(j-(i>s)-(i>t))%P+1ll*f[(i-1)&1][j+1]*j%P)%P; else f[i&1][j]=f[(i-1)&1][j-1]+f[(i-1)&1][j]; } write(f[n&1][1]); }
T4 最短路
还没有打。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步