【CF Gym 100637K】 Microcircuits 【DP】【环上n个点,问不相交的连k条线的方案数】

本文探讨了一个关于在圆周上放置n个点,并求出能够连接k条非交叉线段的不同方案数量的问题。通过动态规划的方法,文章提供了一种有效的解决方案,并给出了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传送门:

描述:

K. Microcircuits
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You probably know how microcircuits look like. First of all it is important to pay special attention to connections. Contacts on the circuit are connected by lines. If two lines do not intersect then there is no connection between respective contacts.

You are holding a circular circuit with n contacts around the borderline. You have to calculate the number of possibilities to put exactly knon-intersecting lines each connecting two contacts.

Input

Single line contains two integers n and k (1 ≤ k ≤ n ≤ 40).

Output

Output the required number.

Examples
input
4 2
output
2
input
4 3
output
0

题意:

给你n个点,将这些点放在一个环上,问你不相交的连k条线的方案数。(没有重点)

思路:

dp[i][j]表示i个点连j条线的方案数,那么新加一个点i,

情况1:i没有和之前的点相连,方案数为dp[i-1][j];

情况2:i和p号点相连(0<p<j),那么就i-p这条线把所有点划分成两部分,然后枚举一些子问题的连边数,方案数为sum( dp[p-1][q]*dp[i-1-p][j-1-q] ) (0<=q<j)

复杂度:

O(n^4)

代码:

#include <bits/stdc++.h>
using  namespace  std;

#define ll __int64
#define rep(i,k,n) for(int i=k;i<=n;i++)

template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}

ll dp[50][50];

int  main(){
  int k,n;
  read(n),read(k);
  rep(i, 0, n)dp[i][0] = 1;
  rep(i, 1, n){
    rep(j, 0, k){
      dp[i][j] = dp[i-1][j];
      rep(p, 1, i-1){
        rep(q, 0, j-1){
          dp[i][j] += dp[p-1][q] * dp[i-1-p][j-1-q];
        }
      }
    }
  }
  print(dp[n][k]);
  return 0;
}



编程竞赛和算法训练平台如 Codeforces Gym 提供了大量高质量的竞赛题目,供选手进行训练和提升。关于 Gym 103409K 题的解决方案或讨论,通常可以通过以下几种方式获取相关信息: 1. **Codeforces Gym 页面**:Gym 103409K 题属于某个特定的比赛或训练集,可以在 Codeforces 的 Gym 页面中查找该题编号的对应比赛,并查看题目描述、提交记录以及可能存在的公开讨论[^1]。 2. **提交记录与代码查看**:在 Codeforces 平台上,用户可以提交代码后查看其他人的提交记录,包括通过的代码。通过阅读其他选手的代码,可以学习不同的解题思路和优化技巧。通常在题页面中击“Standings”可以查看排名,并通过“Hacks”或“Submissions”查看具体代码[^1]。 3. **官方题解与讨论区**:某些比赛会提供官方题解(Editorial),通常在比赛结束后发布。如果该比赛有官方题解,可以在 Codeforces 的博客(Blog)部分查找相关文章。此外,题页面下方的评论区也可能包含选手之间的讨论,有时会涉及解题思路或技巧[^1]。 4. **社区资源**:一些编程竞赛社区如 Codeforces、AtCoder、Topcoder 的论坛,以及 Stack Overflow、Reddit 的 r/learnprogramming 或 r/programming 等板块,也可能存在对该题的讨论。 5. **GitHub 仓库**:许多参赛者会将自己的解题代码整理到 GitHub 上,搜索关键词 "Gym 103409K solution" 或类似内容,可能会找到相关代码或题解。 ### 示例代码结构 以下是一个用于处理典型算法竞赛题的 Python 模板示例,适用于读取输入并输出结果: ```python def main(): import sys input = sys.stdin.read data = input().split() # 示例处理逻辑 n = int(data[0]) a = list(map(int, data[1:n+1])) # 示例输出 print(sum(a)) if __name__ == "__main__": main() ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值