CF GYM
给定 n 个点,标号为 1 ∼ n。现在希望使用若干额外的点将它们连接起来变成一棵树(即无环的连
通图),所有的额外点“无标号”,即互相不做区分。要求 n 个初始点的度恰为 1,所有额外点的度恰为3。 希望你求出所有不同的满足要求的树的数量,即为该题的复杂度。
由于答案很大,你只需要求出答案对 998 244 353 取模的值。
分析
考虑从n-1转移到n n-1时共有2n-5条边 任选一个边加上一个额外点再将额外点与n相连即可
所以f[n]=(2n-5)!!
用scanf!
如果把 NMB 和寝室看做 n × m 网格图上的两个矩形,
有多少种不同的放置方式,使得两个矩形边不相交。特别地,两个相互包含的矩形也被认为是可行的放置方式,两个只有一个角相交的矩形也被认为是不合法的方式。答案对 998 244 353 取模。
组合好题
首先包含的情况 c(n,4)*c(m,4) 相当于每个维度取4个点 外侧和内侧分开分
由于矩形相交等价于x y 均相交
x不相交 y随便选:c(n,4)*c(m,2)*c(m,2)
y不相交 x随便选:c(m,4)*c(n,2)*c(n,2)
而上面两种算了两边包含的情况所以再-2*c(m,4)*c(n,4)
所以tot=c(n,4)*c(m,2)*c(m,2)+c(m,4)*c(n,2)*c(n,2)-c(m,4)*c(n,4)
一共有 n 个土豆会被扔进烤土豆机,其中第 i 个土豆在第 ti 秒被扔进去。
一个土豆在烤土豆机里每多待一秒,烤熟度就会增加 1。也就是说,如果一个土豆在第 a 秒被扔进去,在第 b 秒被捞出来,那么它的烤熟度为 b - a。
捞土豆时,你能够一次把当前烤土豆机里的土豆全部捞出来。但他不想让土豆烤的太熟(因为以后还要用!),所以他每捞一次土豆,他的自闭度就会增加 k 与捞出土豆的烤熟度之和。
你可以捞任意次土豆,每次捞的时间也可以任意选择。他的自闭度一开始为 0。你需要合理安排捞土豆的时机,使得他能够把所有扔进去的土豆捞出来,并且总自闭度最小。
DP
f[i]:在第i个土豆放下去时捞上来的最小
f[i]=min{f[j]+k+(t[i]-t[j+1])+(t[i]-t[j+2])+…+t[i]-t[i-1]}
f[i]=min{f[j]+k+(i-j-1)*t[i]-(s[i-1]-s[j])}
然后斜率优化DP
未优化
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k,t[1000005],s[1000005],f[1000005];
signed main()
{
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++){scanf("%lld",&t[i]);s[i]=s[i-1]+t[i];}
memset(f,0x3f,sizeof(f));
f[0]=0;
for(int i=1;i<=n;i++)
for(int j=0;j<i;j++)
f[i]=min(f[i],k+f[j]+(i-j-1)*t[i]-(s[i-1]-s[j]));
cout<<f[n]<<"\n";
return 0;
}
You are given an array a consisting of n integers.
You have to perform the sequence of n−2 operations on this array:
during the first operation, you either add a2 to a1 and subtract a2 from a3, or add a2 to a3 and subtract a2 from a1;
during the second operation, you either add a3 to a2 and subtract a3 from a4, or add a3 to a4 and subtract a3 from a2;
...
during the last operation, you either add an−1 to an−2 and subtract an−1 from an, or add an−1 to an and subtract an−1 from an−2.
So, during the i-th operation, you add the value of ai+1 to one of its neighbors, and subtract it from the other neighbor.
For example, if you have the array [1,2,3,4,5], one of the possible sequences of operations is:
subtract 2 from a3 and add it to a1, so the array becomes [3,2,1,4,5];
subtract 1 from a2 and add it to a4, so the array becomes [3,1,1,5,5];
subtract 5 from a3 and add it to a5, so the array becomes [3,1,−4,5,10].
So, the resulting array is [3,1,−4,5,10].
An array is reachable if it can be obtained by performing the aforementioned sequence of operations on a. You have to calculate the number of reachable arrays, and print it modulo 998244353.
f[i][j]:第i次i+1的值为j的个数
注意负数的处理即可

浙公网安备 33010602011771号