ACdream 1420 High Speed Trains(容斥原理)

High Speed Trains

Time Limit: 2000/1000MS (Java/Others)  Memory Limit: 128000/64000KB (Java/Others)
Problem Description

      The kingdom of Flatland has n cities. Recently the king of Flatland visited Japan and was amazed by high speed trains Shinkansens going all around the country. Therefore he decided to build the system of high speed trains in Flatland.

      Each high speed train line will be bidirectional and connect exactly two different cities of Flatland. Although there is actually no need of high speed trains in Flatland, the king ordered that there must be at least one high speed train line from each city of Flatland.
      The minister of transportation told the king that there are several train system satisfying his requirements. The king was amazed by the fact and asked the minister to count the number of possible systems.
      Help the minister to calculate the number of train systems.

Input
      The input file contains one integer number n (2 ≤ n ≤ 100)
Output
      Output one integer number — the number of different train systems that can be arranged in Flatland.
Sample Input
4
Sample Output

41

答案 = 所有的情况 - 一个独立的情况 - 两个独立的情况 - .....

D(n) = 2 ^ (n * (n - 1) / 2) - 1 - sum{C(n, k) * dp[n - k] (1 <= k <= n - 1)}


package ds;
/*
 *Author : 2486
 *Memory: 32300 KB		Time: 284 MS
 *Language: Java		Result: Accepted
 *Public:
*/
import java.util.*;
import java.math.*;
import java.io.*;

public class Main{
	static final int MAXN = 100 + 5;
	static final BigInteger Two = new BigInteger("2");
	static BigInteger [][] C = null;
	static BigInteger [] dp = null;
	static void Init(){
		C = new BigInteger[MAXN][MAXN];
		C[0][0] = BigInteger.ONE;
		for(int i = 1;i < MAXN ;i ++){
			C[i][0] = BigInteger.ONE;
			C[i][i] = BigInteger.ONE;
			for(int j = 1;j < i;j ++){
				C[i][j] = C[i - 1][j - 1].add(C[i - 1][j]);
			}
		}
		dp = new BigInteger[MAXN];
		dp[1] = new BigInteger("1");
		dp[2] = new BigInteger("1");
		for(int i = 3;i < MAXN;i ++){
			dp[i] = Two.pow(i * (i - 1) / 2).subtract(BigInteger.ONE);
			for(int k = i - 1;k >= 2;k --){
				dp[i] = dp[i].subtract(dp[k].multiply(C[i][i - k]));
			}
		}
	}
	public static void main(String [] agrv)
	throws IOException
	{
		//System.setIn(new FileInputStream(new File("D:" + File.separator + "imput.txt")));
		Scanner cin = new Scanner(System.in);
		Init();
		while(cin.hasNext()){
			int n = cin.nextInt();
			System.out.println(dp[n]);
		}
	}
}


### 回答1: 写一个用强化学习在MATLAB中实现磁悬浮列车速度跟踪控制的代码。 要写一个用强化学习控制磁悬浮列车速度的代码,您需要了解以下内容: 1. 强化学习的原理:它是一种机器学习方法,通过不断的试错来学习如何解决问题。 2. 磁悬浮列车的运动学:您需要了解磁悬浮列车的动力学模型,以便更好地控制它的速度。 3. MATLAB:您需要熟悉MATLAB编程语言,以便写出代码。 在编写代码之前,您需要先对强化学习算法和磁悬浮列车运动学进行研究,以确保您有足够的知识和技能来完成此任务。推荐使用Q-learning或SARSA算法。 如果您有任何具体问题,请提出,我将尽力帮助您。 ### 回答2: 使用强化学习编写MATLAB中的代码来实现磁悬浮列车速度跟踪控制。 首先,我们需要定义一个磁悬浮列车的速度跟踪控制问题。速度跟踪控制的目标是使磁悬浮列车的实际速度尽可能接近给定的目标速度。我们可以使用强化学习中的一种算法,如深度强化学习(Deep Q-Learning),来解决这个问题。 在MATLAB中,我们需要定义一个环境(Environment)来模拟磁悬浮列车的行为。这个环境包括磁悬浮列车的初始状态,比如初始速度和位置,以及列车的物理特性,如最大加速度和制动力等。我们还需要定义一个动作空间,包含磁悬浮列车可以采取的控制动作,比如加速度值或制动力值。 接下来,我们可以使用强化学习中的Q-Learning算法来训练一个智能体(Agent)。智能体通过与环境的交互来学习如何根据当前状态选择最优的控制动作。训练过程中,智能体会根据环境的反馈,比如奖励或惩罚,来调整自己的决策策略。一次完整的训练过程可以包括多个迭代轮次(Episodes),每个轮次中智能体在环境中执行一系列动作并不断更新自己的Q-函数。 训练完成后,我们可以使用学习到的Q-函数来进行磁悬浮列车的速度控制。智能体将根据当前的状态选择最优的控制动作来调整磁悬浮列车的速度,并与环境进行交互。通过不断的迭代,智能体可以逐渐优化控制策略,使得磁悬浮列车的速度更加接近目标速度。 最后,通过对代码进行调试和优化,我们可以在MATLAB中实现一个高效的磁悬浮列车速度跟踪控制系统,帮助磁悬浮列车实现精准的速度控制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值