编程介的小学生 2017-09-23 13:18 采纳率: 20.5%
浏览 970
已采纳

Expection of String

Problem Description
Frog has just learned how to multiply two numbers. Now he wants to do some exercise.

He wrote a string on the paper, which only contains digits and a single × as the operator. If the × appears at the front or the end of the string, he regards the result as zero, otherwise he does the calculation as a normal multiplication.

After some play, he wonders a new problem: for a initial string, each time he randomly choose two characters and swap their positions. He will do this again and again, say for K times, he wants to know the expected calculation result for the newest string that he gets.

It can be shown that their can be (n2)K ways(Same as (C2n)K) for the whole swap operations, so if the expected result is x, you need to output x×(n2)K as an integer.

Input
First line contains an integer T, which indicates the number of test cases.

Every test case begins with an integers K, which is the numbers of times the Frog can swap characters.

The second line of each test case contains the string Frog plays with, which only contains digits and exactly one multiplication operator, written as '∗'.

⋅ 1≤T≤100.

⋅ the string's length is L.

⋅ for 70% data, 1≤L≤10 and 0≤K≤5.

⋅ for 95% data, 1≤L≤20 and 0≤K≤20.

⋅ for 100% data, 1≤L≤50 and 0≤K≤50.

Output
For every test case, you should output "Case #x: y", where x indicates the case number and counts from 1 and y is the result.

Because y could be very large, just mod it with 109+7.

Sample Input
2
1
1*2
2
1*2

Sample Output
Case #1: 2
Case #2: 6

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-11 10:39
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号