codechef Chef and Left-Right

Problem Description

Chef has a nice complete binary tree in his garden. Complete means that each node has exactly twosons, so the tree is infinite. Yesterday he had enumerated the nodes of the tree in such a way:

  • Let's call the nodes' level a number of nodes that occur on the way to this node from the root, including this node. This way, only the root has the level equal to 1, while only its two sons has the level equal to 2.
  • Then, let's take all the nodes with the odd level and enumerate them with consecutive odd numbers, starting from the smallest levels and the leftmost nodes, going to the rightmost nodes and the highest levels.
  • Then, let's take all the nodes with the even level and enumerate them with consecutive even numbers, starting from the smallest levels and the leftmost nodes, going to the rightmost nodes and the highest levels.
  • For the better understanding there is an example:
                             1
                        /           \
                  2                   4
                /   \                /       \
             3       5           7        9
            / \      /  \          /  \       /  \
           6  8 10 12      14 16   18 20 

Here you can see the visualization of the process. For example, in odd levels, the root was enumerated first, then, there were enumerated roots' left sons' sons and roots' right sons' sons.

You are given the string of symbols, let's call it S. Each symbol is either l or r. Naturally, this sequence denotes some path from the root, where l means going to the left son and r means going to the right son.

Please, help Chef to determine the number of the last node in this path.

Input

The first line contains single integer T number of test cases.

Each of next T lines contain a string S consisting only of the symbols l and r.

Output

Per each line output the number of the last node in the path, described by S, modulo 109+7.

Constraints

  • 1 ≤ |T| ≤ 5
  • 1 ≤ |S| ≤ 10^5
  • Remember that the tree is infinite, so each path described by appropriate S is a correct one.

Example

Input:
4
lrl
rll
r
lllr
Output:
10
14
4
13

Explanation

See the example in the statement for better understanding the samples.

题解

找找数字间的规律即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
#define ll long long
#define mod 1000000007
using namespace std;
int T,n;
char a[100010];
ll s;
void ji(int i)
{
	if(a[i]=='l') s=(s<<1)%mod;
	else s=((s<<1)+2)%mod;
}
void ou(int i)
{
	if(a[i]=='l') s=((s<<1)-1)%mod;
	else s=((s<<1)+1)%mod;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	   {scanf("%s",a+1);
	    n=strlen(a+1); s=1;
	    for(int i=1;i<=n;i++)
	       {if(i&1) ji(i);
		    else ou(i);
		   }
		printf("%lld\n",s);
	   }
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
源码编译安装 Chef Solo 分为以下几个步骤: 1. 安装 Ruby 和 RubyGems:Chef Solo 是基于 Ruby 编写的,所以需要先安装 Ruby 和 RubyGems。您可以使用操作系统的包管理器安装,或者从官方网站下载源代码编译安装。安装完成后,请验证 Ruby 和 RubyGems 是否安装成功。 2. 安装 Chef 和依赖组件:Chef Solo 是 Chef 的一个独立组件,需要先安装 Chef 和依赖组件。您可以使用 RubyGems 安装,命令如下: ``` gem install chef ``` 安装完成后,请验证 Chef 是否安装成功。 3. 下载 Chef Solo 源代码:您可以从官方网站下载最新版本的 Chef Solo 源代码,或者使用以下命令从 GitHub 上下载: ``` git clone https://github.com/chef/chef.git ``` 4. 编译和安装 Chef Solo:使用以下命令编译和安装 Chef Solo: ``` cd chef/chef-solo gem build chef-solo.gemspec gem install chef-solo-<version>.gem ``` 其中,`<version>` 是 Chef Solo 的版本号,您需要将其替换为实际的版本号。安装完成后,请验证 Chef Solo 是否安装成功。 5. 配置 Chef Solo:将您的 Chef Solo 配置文件(通常是 solo.rb 和 json 文件)放置在合适的目录下,并确保您的配置文件正确。可以使用 `chef-solo -c <config_file>` 命令来验证配置文件是否正确。 6. 使用 Chef Solo:使用 `chef-solo -c <config_file>` 命令来启动 Chef Solo,并运行您的 Chef 配方(cookbooks)。 希望这个步骤对您有所帮助,如果您有其他问题,请随时问我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值