编程介的小学生 2019-04-18 22:46 采纳率: 20.5%
浏览 184

机器人的比赛的一个算法问题,用到排列数,怎么用C语言的程序的编写来实现的

Problem Description

Do you still remember the movie "I, robot" ? In that movie, Sunny is a very special, unique robot who can dream! As we known, robot is a machine installed with artificial intelligence, and it can't response to the situations which are not contained in the pre-designed programs. But the creator of Sunny detects that the logic sequences existed in the robot would change under some particular cases, e.g. magnetic field, noises etc. He called this unpredictable sequence ghosts in the robot because these random combination of 1s and 0 s could yield unpredictable behaviors of robots, it was terrible! In order to detect this situation as soon as possible, you should help the prof. via your outstanding programming skills.
You would be given a sequence with the length of N, and this sequence is only contained 0 and 1.Based on the professor's recent research data, the sequence could have at most F successive bits flipped(that means 0 changes to 1, and 1 changes to 0) and could have at most R successive bits remained the same. Based on these situations, you should calculate the maximum number of 1 in the sequence after those changes.

Input
The input would have multiple test cases, each test case has two lines, The first line contains two integer R and F(1 <= R <= 50, 1 <= F <= 50), indicating the number of the digits remain the same and the number of the digits flipped respectively. the second line is a sequence only comprises of 0 and 1, whose length is between 1 and 1000.The input would end when R == 0 and F == 0.

Output
For each case, print a line with the maximum number of 1 left in the sequence.

Sample Input
4 1
1111
2 2
1111
0 0

Sample Output
4
3

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝