思维dp ---- Codeforces Round #722 (Div. 1) B. Kavi on Pairing Duty [思维dp + 数学]

题目大意:

2 n 2n 2n个点两两相连形成n对,对于任意两个点对A和B,要求至少满足其中一条:
1.A和B的某一个完全包含于另一个中
2.A和B的长度相等.问你一共有多少种方案.

解题思路:

题解:假设第一个区间的左端点为1,右端点为x,对x分两种情况来分析.

1. x > n x>n x>n,那么所有大于 x x x的点,因为它不完全包含于 [ 1 , x ] [1,x] [1,x],所以它们的长度都相同,左端点确定,那么在 [ 1 , x ] [1,x] [1,x]内,就会有一些点空出来,这些点我们可以看成是一种子情况,所以可以用前缀和来维护.注意:就是这里着中间有空点的情况!那么要用前缀和维护
在这里插入图片描述

2. x ≤ n x≤n xn,那么所有的点对长度相同,我们连接 1 1 1 x x x后, [ 1 , x ] [1,x] [1,x]中间会空出 x − 2 x−2 x2个点,将中间的这些点和对应的右端点连接,全部连完后,最右端点扩展到了 x + x − 2 x+x−2 x+x2,即 2 ∗ ( x − 1 ) 2∗(x−1) 2(x1),那么我们可以将这看成一个完整的块,这个块有 2 ∗ ( x − 1 ) 2∗(x−1) 2(x1)个点,很明显,只有 2 n m o d 2 ∗ ( x − 1 ) = 0 2nmod2∗(x−1)=0 2nmod2(x1)=0时才合法, 所以 x − 1 x−1 x1一定要是 n n n的因子(不含1).

那么我们就能得出递推式子: d p [ i ] = p r e [ i − 1 ] + d i v i s o r s [ i ] . dp[i]=pre[i−1]+divisors[i]. dp[i]=pre[i1]+divisors[i].

#include <bits/stdc++.h>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define LLF 0x3f3f3f3f3f3f3f3f
#define f first
#define s second
#define endl '\n'
using namespace std;
const int N = 2e6 + 10, mod = 998244353;
const int maxn = 1500010;
const long double eps = 1e-5;
const int EPS = 500 * 500;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
template<typename T> void read(T &x)
{
   x = 0;char ch = getchar();ll f = 1;
   while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
   while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
   read(first);
   read(args...);
}

int divs[maxn],a[maxn];

int main() {
   IOS;
   int n;
   cin >> n;    
   for(int i = 1; i < maxn; ++ i)
      for(int j = i; j < maxn; j += i)
         divs[j] ++;
    a[1] = 1;
    for(int i = 2; i <= n; ++ i)
       a[i] = (2 * a[i - 1] % mod + divs[i]) % mod;
    cout << (a[n] - a[n - 1] + mod) % mod;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值