Problem Description
These few days, Baby Ming is addicted to playing a matrix game.Given a n∗m matrix, the character in the matrix(i∗2,j∗2) (i,j=0,1,2...) are the numbers between 0−9. There are an arithmetic sign (‘+’, ‘-‘, ‘∗’, ‘/’) between every two adjacent numbers, other places in the matrix fill with ‘#’.The question is whether you can find an expressions from the matrix, in order to make the result of the expressions equal to the given integer sum. (Expressions are calculated according to the order from left to right)Get expressions by the following way: select a number as a starting point, and then selecting an adjacent digital X to make the expressions, and then, selecting the location of X for the next starting point. (The number in same place can’t be used twice.)
Input
In the first line contains a single positive integer T, indicating number of test case.In the second line there are two odd numbers n,m, and an integer sum(−1018<1018, divisor 0 is not legitimate, division rules see example)In the next n lines, each line input m characters, indicating the matrix. (The number of numbers in the matrix is less than 15)1≤T≤1000
Output
Print Possible if it is possible to find such an expressions.Print Impossible if it is impossible to find such an expressions.
Sample Input
33 3 241*1+#*2*81 1 113 3 31*0/#*2*6
Sample Output
Possible Possible Possible
Hint
The first sample:1+2*8=24 The third sample:1/2*6=3
Source
-
- 题意: 给一个矩形,两个0~9的数字之间隔一个数学运算符(‘+’,’-‘,’*’,’/’),其中’/’表示分数除,再给一个目标的值,问是否存在从一个数字出发,以数字之间的运算符为运算,得到这个目标值;(每个数字只能用一次,其实说白了就是dfs..);可以则输出(Impossible),否则输出(Possible);
直接dfs暴力即可,注意要用double类型来计算
AC代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include
别人的AC代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include2 #include 3 #include 4 #include 5 #include 6 #include