Game of Dice Gym
来源:互联网 发布:淘宝达人是淘客吗 编辑:程序博客网 时间:2024/05/06 13:48
#include<stdio.h>#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<map>#define LL long longusing namespace std;const int MOD=1e9+7;int diec[20][10];map<LL,int> M;long long ans=0;int x;long long pow(long long x,int n){ long long y=1; long long u=x%MOD; while(n) { if(n&1) y=y*u%MOD; n>>=1; u=u*u%MOD; } return y;}void dfs(int s,int e,int flag,long long res){ if(e==s) { if(flag) { ++M[res]; } else { ans+=M[x*pow(res,MOD-2)%MOD]; } } else { for(int i=0;i<6;i++) { dfs(s+1,e,flag,res*diec[s][i]%MOD); } }}int main(){ int T; scanf("%d",&T); while(T--) { ans=0; M.clear(); int n; scanf("%d%d",&n,&x); for(int i=0;i<n;i++) { for(int j=0;j<6;j++) { scanf("%d",&diec[i][j]); } } dfs(0,n/2,1,1); dfs(n/2,n,0,1); cout<<ans<<endl; }}
It is always fun to play with dice, here is one interesting game:
You are given n fair dice with 6 faces, the faces does not necessarily have values from 1 to 6 written on them. instead, they can have any values from 1 to 100 written on them.
Suppose you threw the n dice one after another, let us define the result of the throws as the multiplication of the numbers you get from each dice mod109 + 7.
You task is to find how many different ways you can get the result of the dice throws equal tox.
The first line contains an integer T, whereT is the number of test cases.
The first line of each test case contains two integers n and x (1 ≤ n ≤ 14) (0 ≤ x < 109 + 7), wheren is the number of the dice and x is the required result from the throws.
Then n lines follow, the ith line contains 6 integersfi1, fi2, ..., fi6(1 ≤ fij ≤ 100), giving the values ofith dice's faces.
For each test case, print a single line containing how many different ways you can get the result of the dice throws equal tox
33 91 2 3 4 5 61 2 3 4 5 61 2 3 4 5 65 61 2 9 9 9 91 2 9 9 9 91 3 9 9 9 91 3 9 9 9 91 6 9 9 9 95 999999937100 1 1 1 1 1100 1 1 1 1 1100 1 1 1 1 1100 1 1 1 1 1100 1 1 1 1 1
351
题意: 你有n个骰子,每个骰子的六个面已经给出,问你有多少种可能 使得这些骰子投出的数的乘积对1e9+7取模后=x、
一个裸的折半搜索题。
一开始想直接暴搜,然后发现复杂度高达6^14 肯定过不了。
然后发现这是个配对问题,所以可以用折半搜索。
对前半部分用map存一下搜索后的结果。
然后后半部分搜索时配对一下就行。
由于涉及到除法取模,快速幂求一下逆元就好。
复杂度应该是6^(n/2)再乘个log。
- Game of Dice Gym
- Gym-100502D Dice Game
- Game of Dice GYM101532E
- Game of Cards Gym
- SOJ.Dice Game
- Sicily 13907. Dice Game
- CSU1577: Dice Game
- csu 1577: Dice Game
- ACTF Dice Game Writeup
- Gym 100703F Game of words 动态规划
- Gym - 100703G-G-Game of numbers-暴力
- Codeforces Gym 100650C The Game of Efil DFS
- GYM 101128 G.Game of Cards(博弈论)
- GYM 101147 A.The game of Osho(博弈论)
- GYM 101128 D.Dice Cup(概率)
- HDU 3959 Board Game Dice
- projecteuler No.205 Dice Game
- nyoj 408 Board Game Dice
- 在LINUX 16.04下 用QT5.7编译qgroundcontrol地面控制站
- 单墫老先生提出的问题的初步思考
- ubuntu 14.04 anm64修复 不能关机、重启、注销的问题
- idea打包SpringBoot项目打包成jar包和war
- 第四周项目一
- Game of Dice Gym
- SpringMVC Controller单例和多例
- 【项目实战】---为EasyUI DataGrid的某一动态加载数据列添加超链接,点击超链接触发Onclick方法
- Xcode 中的相对路径与绝对路径的相关设置
- 自定义控件
- WIN10 右键 powershell 修改
- POJ 2676 Sudoku 笔记
- 第四周项目二
- K:利用System.getProperties()方法获得的虚拟机进程的信息