ZOJ 3747 Attack on Titans

[递推dp] zoj 3747 Attack on Titans 题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5170 Attack on Titans Time Limit: 2 Seconds      Memory Limit: 65536 KB Over centuries ago, mankind faced a new enemy, th 阅读详情

关键字:动态规划,带限制条件的计数递推

题目:
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.

思路:
1.将至少的情况转换为至多的情况
事件A={至多n个G&&至多k个R}
事件B={至多m-1个G&&至多kgeR}
事件A-B={至少有m个G}

2.设dp[i][0] dp[i][1] dp[i][2]分别表示第i个位置(从1开始)为G、R、P时至多有u个连续G,至多有v个连续R的个数
设sum = dp[i-1][0]+dp[i-1][1]+dp[i-2][2]
当第I个为P时,无限制条件,dp[i][2] = sum
当第I个为G时,
i <= u时,dp[i] = sum
i == u+1时,dp[i] = sum - 1(此时减去从1至u全为G的情况(只有1种..))
i > u+1 时,dp[i] = sum - dp[i-u-1][1] - dp[i-u-1][2](此时减去从i-u至i-1全为G的情况(有dp[i-u-1][1] + dp[i-u-1][2]种))
当第I个为R时,同理。

链接:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5170

代码:

#include <iostream>
#include <fstream>
#include <cstdio>
using namespace std;
#define ll long long
const int maxn = 1000010;
const int M = 1000000007;
ll dp[maxn][3];
int n;

ll f(int u, int v){
    ll sum = 0;
    dp[0][0] = 1;
    dp[0][1] = dp[0][2] = 0;

    for(int i = 1; i <= n; ++i){
        sum = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) % M;

        dp[i][2] = sum;

        if(i <= u) dp[i][0] = sum;
        else if(i == u + 1) dp[i][0] = (sum - 1)%M;
        else dp[i][0] = (sum - dp[i - u - 1][1] - dp[i - u - 1][2])%M;

        if(i <= v) dp[i][1] = sum;
        else if(i == v + 1) dp[i][1] = (sum - 1)%M;
        else dp[i][1] = (sum - dp[i - v - 1][0] - dp[i - v - 1][2])%M;
    }
    return (dp[n][0] + dp[n][1] + dp[n][2]) % M;
}

int main(){
//    freopen("a.txt", "r", stdin);
    int m, k;
    while(scanf("%d %d %d", &n, &m, &k) != EOF){
        printf("%lld\n", (((f(n, k) - f(m - 1, k)) % M) + M) % M); //取正值..
    }
}
施密特触发电路详细原理介绍 我们想获得矩形脉冲,有种方法是可以采用整形的方法获得矩形脉冲,但前提是可以找到频率和幅度都符合要求的电压信号。 我们设定矩形脉冲的几个指标。 施密特电路是脉冲波形变换中一种常采用的电路,主要有以下两个特点: 1.输入电平从低电平上升过程中电路状态转换为对应的输入电平,与高电平下降过程中对应的输入转换电平不同。 2.通过电路内部的正反馈使输出电压波形的边沿变得很陡。 施密特电路的结构和工作原理 我们先从模电的角度来分析此电路的工作原理。 此电路是通过公共发射极电阻耦合的两级正反馈放大器。 v1输入为低电平 阅读详情

相关推荐

gitlab远程子仓库配置SSH - 保姆级教程

在网上搜索了一些方法,但是不够详细,走了好多弯路,所以记录下配置SSH的详细过程吧。

是菠萝的博客 1万+

【dp】递推 zoj3747

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

LATTE 299

保姆级教程:在Windows上用Python+OpenCV调用海康工业相机(附MVS配置避坑指南)

本文提供了一份详细的Windows环境下使用Python和OpenCV调用海康工业相机的保姆级教程,涵盖MVS配置避坑、相机连接、图像获取与格式转换等关键步骤。特别针对工业相机取流中的常见问题,如独占访问控制和多相机协同工作,提供了实用解决方案,帮助开发者快速实现稳定的图像采集系统。

weixin_29228781的博客 400

DP+条件约束

Attack on TitansOver 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 e

Bowen的博客 894

QGIS效率提升神器:qgis_mcp插件+VSCode联合工作流配置全解析

本文详细解析了如何通过配置qgis_mcp插件与VSCode的联合工作流,实现语音控制和代码自动化来大幅提升QGIS操作效率。该方案将自然语言交互与现代编辑器生态结合,为地理信息专业人士构建了智能、高效的全新工作模式,彻底改变传统GIS操作方式。

weixin_29228203的博客 191

树莓派Bookworm系统避坑指南:3种方法解决pip install报错externally-managed-environment

本文详细解析树莓派Bookworm系统中pip install报错externally-managed-environment的成因,并提供三种实用解决方案:使用虚拟环境(venv)隔离项目依赖、通过pipx管理全局Python工具,以及理解风险后的系统安装方法。帮助开发者安全高效地管理Python环境,避免系统冲突。

android的专栏 766

ZOJ 3747 Attack on Titans

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 w

wust_ZJX的专栏 2193

计组头哥实验 实验三 MIPS寄存器实验

了解 MIPS 寄存器文件基本概念,进一步熟悉多路选择器、译码器、解复用器等 Logisim 组件的使用,并利用相关组件构建 MIPS 寄存器文件。

gdz0007的博客 1万+

Attack on Titans ZOJ - 3747(分类dp)

#include <iostream> #include <cstdio> using namespace std; typedef long long LL; const int mod = 1000000007; const int maxn = 2000010; LL dp[maxn][3]; int n,m,k; LL solve(int u,int v){ ...

leekerian的博客 229

Synopsys工具filter命令:从数据筛选到高效IC设计的实战指南

在数字集成电路设计流程中,数据筛选与查询是工程师处理海量网表、时序报告和设计约束的核心需求。其原理在于通过声明式查询语言,直接对设计对象(如单元、网络、路径)的属性进行逻辑判断与模式匹配,从而精准定位目标。这种技术价值在于将工程师从繁琐的过程式脚本循环中解放出来,大幅提升代码可读性与运行效率,直接调用工具内置的高性能查询引擎。在实际应用场景中,它广泛用于物理与时序联合分析、层次化模块操作、动态约束生成以及自动化报告生成。本文聚焦于Synopsys工具链中filter命令的高阶用法,深入解析其表达式语法、正则

weixin_28007513的博客 577

zynq+LWIP 裸机双网口实现(MIO+EMIO)+程序下载

芯片型号: ZYNQ: XC7Z010clg400开发软件:Vivado2022 + Xilinx Vitis 2022网卡芯片:RTL8211FDI(需要根据网口芯片型号修改对应的硬件配置代码。

thinking in 小宇宙 3409

Attack on Titans ZOJ - 3747

Attack on Titans 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3747 题目大意: 给N个士兵排队,每个士兵三种G、R、P可选,求至少有连续M个G士兵,最多有连续K个R士兵的排列的种数。 输入: There are multiple test cases. For each case, ther...

qq_40967246的博客 290

C#串口通信从入门到精通(1)——硬件接线

RS-232接口一般都是9针的,有公母头(针头和孔头),为了便有理解以下都称为针头和孔头,针头就是露出来的针,孔头就是9个孔,总共使用3条线进行通信,一条用于发送,一条用于接收,另外一根是GND地线,由于线路的功能是永久性的,设置连接时,必须确保一个节点的发送线与另一个节点的接收线相连,反之亦然,RxD(PC的接收线)连接到TxD(传感器电子设备的发送线),TxD(PC的发送线)连接到RxD(传感器电子设备的发送线)。两条线路的电平都是相对于GND的。因此,GND也必须连接,但不能将GND与屏蔽连接。

qq_34059233的博客 1万+

Attack on Titans ZOJ 3747

Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3747 64-bit integer IO format: %lld Java class name: MainOver centuries ago, mankind faced a new enemy,

qq_33688997的博客 315

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Attack on Titans ZOJ - 3747 dp

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. Lucki

liluoyu_1016的博客 312

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Attack on Titans ZOJ - 3747 DP

题目链接:Attack on Titans ZOJ - 3747 三种士兵,G、R、P,有序排成总人数为n 的队伍,其中要有至少m个G连续,至多k个R连续,求有多少种排列方案。至少m个连续不好计算,但是至多m个连续好计算,只要保证没有m个以上的连续出现就好了。那么至少m个 == 至多n个-至多m-1个dp[i][j]:=前i个士兵,第i个为G(R,P)时,满足至多m个G连续,至多k个R连续的方案数为

litmxs的博客 436

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

ZOJ 3747 Attack on Titans 带限制的递推DP

Attack on Titans ZOJ - 3747 总共有 nnn 个人,编号 1∼n1\sim n1∼n,三个种类 A,B,CA,B,CA,B,C,要求有连续不少于 mmm 个 AAA 种类的人,连续不多于 kkk 个 BBB 种类的人,问这 nnn 个人的有多少种组合方式? 思路参考 https://blog.youkuaiyun.com/wust_ZJX/article/details/468099...

wineandchord 178

ZOJ3747 Attack on Titans(容斥dp)

传送门 三个数字1,2,31,2,31,2,3组成长度nnn的序列 000的话无所谓 至少出现mmm个连续111 至多出现kkk个连续222 发现至少并不好求 转而求至多出现kkk个连续222,至多出现m−1m-1m−1个连续111,方案记作ans1ans_1ans1​ 然后求不限制111,至多出现kkk个连续222,方案数记住ans2ans2ans2 最终答案就是ans2−ans1ans2-ans1ans2−ans1 T1T1T1 我们先来求ans2ans2ans2,假如不考虑任何限制,定义f[i][j

jziwjxjd的博客 435

titans java_ZOJ 3747 Attack on Titans

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. Lucki...

weixin_39667398的博客 156

ZOJ - 3747 Attack on Titans

题意就是输入三个数字 n m k, 给n个士兵排队 每个士兵三种G,R,P可选,求至少有m个连续的G士兵和最多有k个连续的R士兵的排列总和 分析题意:在n个士兵中至少有m个连续的G士兵和最多有k个连续的R士兵的排列总和 就等于 (在n个士兵中最多有k个连续的R士兵和最多有n个连续的G士兵) - (在n个士兵中最多有k个连续的R士兵和最多有m-1个连续的G士兵) #include...

weixin_34344677的博客 116

ZOJ 3747 Attack on Titans

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

阑珊记忆 408

(zoj3747) Attack on Titans

今天开始做DP,今天的这个DP是带有限制条件的,并且和组合数学有关。 首先这个题第一个突破点是将至少条件转化为至多的条件,这个很重要,决定了解题的方向。因为在规划问题状态的时候很难对至少进行处理,并且不易进行状态的划分。 这样的话,将问题就转化成了,至多连续n个G,至多连续k个R 减去 至多连续 m-1 个G,至多连续K个R,现在问题的状态就转换成了求至多上面两个状态的方法数。 然后考虑...

AC_jie的博客 869

Attack on Titans ZOJ - 3747(限制条件下的DP递推)

Attack on Titans 题目链接:ZOJ - 3747题意:选出N个士兵编号1~N, 一共三种士兵, G,R,P三种, 士兵总数是无限大;G士兵至少有M个连续地, R士兵至多有...

Sirius_han的博客 502
上一篇: hdu 2044 一只小蜜蜂...
下一篇: hdu 2602 Bone Collector(01背包)
SkyeBCI
博客等级 码龄9年 231粉丝 211原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值