ELI'S CURIOUS MIND

问题 C: ELI'S CURIOUS MIND

时间限制: 1 Sec  内存限制: 128 MB
提交: 54  解决: 46
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Eli is a teenager who loves to study chemistry. She recently joined a chemistry research lab. 
Dr.  Phil  wants  her  to  just  play  around  with  some  chemicals  and  observe  their  reaction. 
Therefore, he gave her a one-row tray of test tubes with the different chemical inside of them and told her: 
"Mix these chemical together anyhow that you like, but the you have to follow two rules: 
1.  Never make a mixture that has two chemicals that their tubes are next to each other. 
2.  Keep adding more chemical to the mixture until it is not violating the new rule. " 
For  example,  in  the  image  you  can  see  she  was  given  5  tubes  and  she  is  able  to  make  4 different mixture without violating the rule: {1,3,5}, {2,4}, {2,5}, {1,4}. 
But she cannot mix 1 and 3 only because she still can add 5 without violating the rules.  
She is curious to know how many different mixtures she  can  make  without  violating  the  rule  with  any given  number  of  tubes.  That's  why  she  asks  you write a code to calculate it for her.  

输入

The input will consist of a sequence of numbers N,  1≤N≤ 76. Each number will be on a separate line. The input will be terminated by 0. 

输出

Output the number of different mixture she can make without violating the rule mentioned above on a single line as show in the sample. The number of all subsets will be less than 231 . 

样例输入

1
2
3
4
5
30
0

样例输出

Case #1: 0
Case #2: 0
Case #3: 1
Case #4: 3
Case #5: 4
Case #6: 4410

队友:这题没思路,你打个表看看

我:好

3min后

我:这表咋打啊???

n min 后

我:表打好了,快来看

队友:嗯,写数组里吧,这题A了

本来想打表找找规律来着,一不小心把答案都打出来了qwq

打表代码

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int ans,n;
void dfs(int t)
{
    if(t>n)
        return;
    if(t+2<=n)
    {
        //printf("%d--->%d,",t,t+2);
        if(t+4>n)
            ans++;//,printf("\n");
    }

    dfs(t+2);
    if(t+3<=n)
    {
        //printf("%d--->%d,",t,t+3);
        if(t+5>n)
            ans++;//,printf("\n");
    }

    if(t+2<=n)
        dfs(t+3);
}
int main()
{
    for(int i=1;i<=76;i++)
    {
        //scanf("%d",&n);
        n = i;
        ans = 0;
        dfs(1);
        dfs(2);
        printf("%d --->%d\n",i,ans);
    }
    return 0;
}

好像是递推来着,不管了,暴力过了就是过了

 

Ac

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[100]=
{
    0,
    0,
    0,
    1,
    3,
    4,
    5,
    7,
    9,
    12,
    16,
    21,
    28,
    37,
    49,
    65,
    86,
    114,
    151,
    200,
    265,
    351
    ,465
    ,616
    ,816
    ,1081
    ,1432
    ,1897
    ,2513
    ,3329
    ,4410
    ,5842
    ,7739
    ,10252
    ,13581
    ,17991
    ,23833
    ,31572
    ,41824
    ,55405
    ,73396
    ,97229
    ,128801
    ,170625
    ,226030
    ,299426
    ,396655
    ,525456
    ,696081
    ,922111
    ,1221537
    ,1618192
    ,2143648
    ,2839729
    ,3761840
    ,4983377
    ,6601569
    ,8745217
    ,11584946
    ,15346786
    ,20330163
    ,26931732
    ,35676949
    ,47261895
    ,62608681
    ,82938844
    ,109870576
    ,145547525
    ,192809420
    ,255418101
    ,338356945
    ,448227521
    ,593775046
    ,786584466
    ,1042002567
    ,1380359512
    ,1828587033
};
int main()
{
    int n;
    int Case=1;
    while(~scanf("%d",&n))
    {
        if(n==0)
            break;
        printf("Case #%d: %d\n",Case++,a[n]);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值