hdu 1008 Count 101 n个0-1串的种类,不能包括101

Count 101

Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 267    Accepted Submission(s): 106
Problem Description
You know YaoYao is fond of his chains. He has a lot of chains and each chain has n diamonds on it. There are two kinds of diamonds, labeled 0 and 1. We can write down the label of diamonds on a chain. So each chain can be written as a sequence consisting of 0 and 1.
We know that chains are different with each other. And their length is exactly n. And what’s more, each chain sequence doesn’t contain “101” as a substring.
Could you tell how many chains will YaoYao have at most?
 
Input
There will be multiple test cases in a test data. For each test case, there is only one number n(n<10000). The end of the input is indicated by a -1, which should not be processed as a case.
 
Output
For each test case, only one line with a number indicating the total number of chains YaoYao can have at most of length n. The answer should be print after module 9997.
 
SampleInput
3
4
-1
 
SampleOutput
7
12
Hint
We can see when the length equals to 4. We can have those chains: 0000,0001,0010,0011 0100,0110,0111,1000 1001,1100,1110,1111

 

 

/*a[n][0][0]=a[n-1][0][0]+a[n-1][1][0];
a[n][0][1]=a[n-1][0][0];
a[n][1][0]=a[n-1][0][1]+a[n-1][1][1];
a[n][1][1]=a[n-1][0][1]+a[n-1][1][1];*/
#include<iostream>
#include<cstdio>
using namespace std;
int a[10001][2][2];
int ans[10001];
int main()
{
    ans[1]=2;ans[2]=4;
    a[2][0][0]=1;a[2][0][1]=1;a[2][1][0]=1;a[2][1][1]=1;
    for(int n=3;n<=10000;n++)
    {
        a[n][0][0]=(a[n-1][0][0]+a[n-1][1][0])%9997;
        a[n][0][1]=a[n-1][0][0]%9997;
        a[n][1][0]=(a[n-1][0][1]+a[n-1][1][1])%9997;
        a[n][1][1]=(a[n-1][0][1]+a[n-1][1][1])%9997;
        ans[n]=(a[n][0][0]+a[n][0][1]+a[n][1][0]+a[n][1][1])%9997;
    }
    int n;
    while(scanf("%d",&n)==1)
    {
        if(n<0) break;
        printf("%d/n",ans[n]);
    }
    return 0;
}

7-10 天梯赛的赛场安排分数 25 全屏浏览 切换布局 作者 陈越 单位 浙江大学 天梯赛使用 OMS 监考系统,需要将参赛队员安排到系统中的虚拟赛场里,并为每个赛场分配一位监考老师。每位监考老师需要联系自己赛场内队员对应的教练们,以便发放比赛账号。为了尽可能减少教练监考的沟通负担,我们要求赛场的安排满足以下条件: 每位监考老师负责的赛场里,队员人数不得超过赛场规定容量 C; 每位教练需要联系的监考人数尽可能少 —— 这里假设每所参赛学校只有一位负责联系的教练,且每个赛场的监考老师都不相同。 为此我们设计了多轮次排座算法,按照尚未安排赛场的队员人数从大到小的顺序,每一轮对当前未安排的人数最多的学校进行处理。记当前待处理的学校未安排人数为 n: 如果 n≥C,则新开一个赛场,将 C 位队员安排进去。剩下的人继续按人数规模排队,等待下一轮处理; 如果 n<C,则寻找剩余空位数大于等于 n 的编号最小的赛场,将队员安排进去; 如果 n<C,且找不到任何非空的、剩余空位数大于等于 n 的赛场了,则新开一个赛场,将队员安排进去。 由于近年来天梯赛的参赛人数快速增长,2023年超过了 480 所学校 1.6 万人,所以我们必须写个程序来处理赛场安排问题。 输入格式: 输入第一行给出两个正整数 N C,分别为参赛学校数量每个赛场的规定容量,其中 0<N≤500010≤C≤50。随后 N 行,每行给出一个学校的缩写(为长度不超过 6 的非空小写英文字母该校参赛人数(不超过 500 的正整数),其间以空格分隔。题目保证每所学校只有一条记录。 输出格式: 按照输入的顺序,对每一所参赛高校,在一行中输出学校缩写该校需要联系的监考人数,其间以 1 空格分隔。 最后在一行中输出系统中应该开设多少个赛场。 输入样例: 10 30 zju 30 hdu 93 pku 39 hbu 42 sjtu 21 abdu 10 xjtu 36 nnu 15 hnu 168 hsnu 20 输出样例: zju 1 hdu 4 pku 2 hbu 2 sjtu 1 abdu 1 xjtu 2 nnu 1 hnu 6 hsnu 1 16
最新发布
03-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值