Attack on Titans(递推dp 条件限制)

本文介绍了一道基于《进击的巨人》背景的算法题目,任务是在限制条件下计算组建特殊作战小队的方法数量。

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

Attack on Titans

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Over centuries ago, mankind faced a new enemy, the Titans. The difference of power between mankind and their newfound enemy was overwhelming. Soon, mankind was driven to the brink of extinction. Luckily, the surviving humans managed to build three walls: Wall Maria, Wall Rose and Wall Sina. Owing to the protection of the walls, they lived in peace for more than one hundred years.

But not for long, a colossal Titan appeared out of nowhere. Instantly, the walls were shattered, along with the illusory peace of everyday life. Wall Maria was abandoned and human activity was pushed back to Wall Rose. Then mankind began to realize, hiding behind the walls equaled to death and they should manage an attack on the Titans.

So, Captain Levi, the strongest ever human being, was ordered to set up a special operation squad of N people, numbered from 1 to N. Each number should be assigned to a soldier. There are three corps that the soldiers come from: the Garrison, the Recon Corp and the Military Police. While members of the Garrison are stationed at the walls and defend the cities, the Recon Corps put their lives on the line and fight the Titans in their own territory. And Military Police serve the King by controlling the crowds and protecting order. In order to make the team more powerful, Levi will take advantage of the differences between the corps and some conditions must be met.

The Garrisons are good at team work, so Levi wants there to be at least M Garrison members assigned with continuous numbers. On the other hand, members of the Recon Corp are all elite forces of mankind. There should be no more than K Recon Corp members assigned with continuous numbers, which is redundant. Assume there is unlimited amount of members in each corp, Levi wants to know how many ways there are to arrange the special operation squad.

Input

There are multiple test cases. For each case, there is a line containing 3 integers N (0 < N < 1000000), M (0 < M < 10000) and K (0 < K < 10000), separated by spaces.

Output

One line for each case, you should output the number of ways mod 1000000007.

Sample Input
3 2 2
Sample Output
5
Hint

Denote the Garrison, the Recon Corp and the Military Police as G, R and P. Reasonable arrangements are: GGG, GGR, GGP, RGG, PGG.

题意:有三个兵团 GRP,现在需要组成N人团队,至少调动M个连续G士兵,至多调动K个连续R士兵,问有多少种组合情况

思路:由于又是至多又是至少没办法处理,所以统一转换成至多,对于事件A={至多N个G士兵连续},事件B={至多m-1个G士兵连续},那么A-B={连续人数在m到n中取值,即至少m个连续士兵}。统一之后,设定一个二维数组,dp[i][3],dp[i][0]表示对于第i个位置,放G士兵,同理,dp[i][1],dp[i][2]分别表示第i个位置放R,和P。

         最大连续u个G,连续v个R;

        对于当前第i个位置,sum=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];

        由于放P对整个没有影响,所以,dp[i][2]=sum;

        对于A事件  

                       当i <= u 时,dp[i][0]=sum;                                             //至多连续u个,那么小于等于u,就可以直接放G

                       当i==u+1时,dp[i][0]=sum-1;                                      // 对于现在这个位置,之前可能出现连续u个的情况,当前要放G,就要减去那一种情况

                       当i>u+1时,dp[i][0]=sum-dp[i-u-1][1]-dp[i-u-1][2];      //此时要减去i前面已经出现连续u个G的情况,即从i-u到i-1这一段都是G,那么i-1-u的位置可以是P或者R,                                                                                                          //于是减去dp[i-u-1][1],dp[i-1-u][2]合起来总共具有的情况数。

         对于B事件                                                                                 //对于B事件同理

                         当i<=v时,dp[i][1]=sum;

                         当i==v+1时,dp[i][1]=sum-1;

                         当i>v+1时,dp[i][2]=sum-dp[i-v-1][0]-dp[i-v-1][2];



Author: ZOU, Xu

#include <stdio.h>
#include <string.h>
const int mod = 1000000007;
const int maxn = 1100000;
long long dp[maxn][3];
long long n, m, k;
long long slove( long long u, long long v)
{
   dp[0][0] = 1;
   dp[0][1] = dp[0][2] = 0;
   for( int i = 1; i <= n; i++)
   {
       long long sum = (dp[i-1][0] + dp[i-1][1] + dp[i-1][2]) % mod;
       dp[i][2] = sum;
       if( i <= u) dp[i][0] = sum;
       if( i == u + 1) dp[i][0] = sum - 1;
       if( i > u + 1)  dp[i][0] = (sum - dp[i - u - 1][1] - dp[i - u - 1][2]) % mod;
       if( i <= v) dp[i][1] = sum;
       if( i == v + 1) dp[i][1] = sum - 1;
       if( i > v + 1)  dp[i][1] = (sum - dp[i - v - 1][2] - dp[i - v - 1][0]) % mod;
      //printf("%d  %d  %d--\n",dp[i][0],dp[i][1],dp[i][2]);
   }
   return (dp[n][0] + dp[n][1] + dp[n][2]) % mod;
}
int main()
{
    while(~scanf("%lld%lld%lld",&n,&m,&k))
    {
         printf("%lld\n",((slove(n, k) - slove(m-1, k))%mod + mod)%mod);
    }

}

n
<think>好的,我需要介绍Titans系统的自动化测试。首先,我要明确用户的需求是什么。他们可能想了解Titans系统的基本概念、自动化测试的组成部分、优势,以及实际应用案例。接下来,我需要确保回答结构清晰,分点说明,同时遵循系统级指令,比如正确使用LaTeX格式。 首先,我应该定义Titans系统自动化测试,可能涉及软件或硬件测试。然后,分模块或流程介绍,比如测试框架、用例管理、执行引擎等。这里要提到常用的工具和框架,比如Selenium或Jenkins,但要注意用户可能指的是特定系统,所以可能需要保持一般性。 然后,列出主要组成部分,每个部分详细一点。例如,测试框架、用例管理、执行引擎、报告分析。每个部分用例子说明,可能用到数学表达式,比如性能测试中的公式,比如计算响应时间的平均值:$\bar{t} = \frac{1}{n}\sum_{i=1}^{n} t_i$。这里要确保用$...$包裹。 接着,说明优势,比如提高效率、减少错误、支持持续集成。可能需要提到覆盖率,比如代码覆盖率公式:$\text{覆盖率} = \frac{\text{覆盖行数}}{\text{总行数}} \times 100\%$。 实际应用案例部分,可以举Web应用和嵌入式系统的例子。这部分需要具体,但可能用户更关心的是通用场景,所以保持例子简洁。 最后,总结要点,强调结构清晰和分步骤的重要性。检查是否所有数学表达式都正确使用了$...$或$$...$$,比如独立公式是否单独成段。例如,性能测试的公式可能需要独立显示: $$P = \frac{\text{成功用例数}}{\text{总用例数}} \times 100\%$$ 确认没有使用Markdown,用纯文本分点。同时保持中文回答,语法正确。可能需要复查是否有遗漏的部分,比如是否提到了持续集成工具如Jenkins,或者异常处理机制。确保每个部分逻辑连贯,帮助用户逐步理解Titans系统的自动化测试。</think>Titans系统自动化测试是一种通过预定义脚本和工具自动执行测试任务的技术,旨在提升软件/硬件系统的质量、效率和可靠性。以下从**核心组成**、**优势分析**和**应用案例**三方面展开说明: --- ### 一、核心组成 1. **测试框架** 通常基于开源工具(如Selenium、Appium)或自研平台,提供基础API和运行环境。例如,HTTP接口测试框架可封装请求发送与结果校验: ```python def test_api_response(): response = requests.get("https://api.example.com/data") assert response.status_code == 200 assert response.json()["status"] == "success" ``` 2. **测试用例管理** 用例以结构化格式(如YAML/JSON)存储,支持动态参数化和数据驱动。例如: ```yaml - name: 登录功能测试 steps: - action: 输入用户名 params: {selector: "#username", value: "$user"} - action: 输入密码 params: {selector: "#password", value: "$pass"} ``` 3. **执行引擎** 分布式调度测试任务,支持并行执行和资源分配。性能测试中常用公式计算平均响应时间: $$\bar{t} = \frac{1}{n}\sum_{i=1}^{n} t_i$$ 其中$t_i$为单次请求耗时,$n$为总请求数。 4. **报告与分析** 生成可视化报告,统计通过率$P$和失败率$F$: $$P = \frac{\text{成功用例数}}{\text{总用例数}} \times 100\%$$ $$F = 100\% - P$$ --- ### 二、优势分析 - **效率提升**:自动化测试速度可达手动的10倍以上,尤其适用于回归测试。 - **精准覆盖**:通过代码覆盖率工具(如JaCoCo)量化测试完整性: $$\text{覆盖率} = \frac{\text{覆盖行数}}{\text{总行数}} \times 100\%$$ - **持续集成(CI)**:与Jenkins/GitLab CI集成,实现代码提交后自动触发测试流水线。 - **异常检测**:通过日志分析和断言机制,快速定位逻辑错误或性能瓶颈。 --- ### 三、应用案例 1. **Web应用测试** - 场景:电商平台购物流程验证 - 方法:使用Selenium模拟用户从浏览商品到支付的完整路径,检查页面跳转和数据库一致性。 2. **嵌入式系统测试** - 场景:智能硬件固件升级验证 - 方法:通过串口通信发送指令,断言固件版本号及传感器数据准确性: $$v_{\text{new}} = v_{\text{old}} + \Delta v$$ 3. **API性能压测** - 场景:高并发下支付接口稳定性测试 - 工具:JMeter模拟每秒千级请求,监控TPS(每秒事务数)和错误率: $$\text{TPS} = \frac{\text{成功事务数}}{\text{测试时长(秒)}}$$ --- ### 四、总结 Titans系统自动化测试通过模块化设计、高效执行和深度分析,显著降低人工成本并提高测试可靠性。实际应用中需结合具体场景选择工具链,并持续优化用例覆盖范围和执行策略。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值