题意 计算给定矩阵链乘表达式需要计算的次数 当前一个矩阵的列数等于后一个矩阵的行数时 他们才可以相乘 不合法输出error
输入是严格合法的 即使只有两个相乘也会用括号括起来 而且括号里最多有两个 那么就很简单了 遇到字母直接入栈 遇到反括号计算后入栈 然后就得到结果了
#include
#include
#include
using namespace std;
const ...
分类:
其他好文 时间:
2014-09-17 10:18:42
阅读次数:
151
题目地址:HDU 1517
NP状态转换。
可以把题目的向上乘变成向下除。这样1是终结状态,设1的时候为必败点。
根据所有能一步到达必败点的点是必胜点,所以[x,x*9]必胜点;根据只能到达必胜点的点是必败点,所以[x*9+1,x*9*2]是必败点.
然后求解。
代码如下:
#include
#include
#include
#include
#include
#inclu...
分类:
其他好文 时间:
2014-09-16 14:17:00
阅读次数:
111
Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices.Since matrix multiplication is associative, the order in which multiplications are performed isarbitrary. How...
分类:
其他好文 时间:
2014-09-13 09:26:28
阅读次数:
210
Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponenti...
分类:
其他好文 时间:
2014-09-13 09:23:34
阅读次数:
197
可以特判出0和1,再统计每行出现了多少种十位上的数就可以了....
没有考虑2的情况似乎也过了......
Multiplication table
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 800 A...
分类:
其他好文 时间:
2014-09-11 02:19:51
阅读次数:
176
时间限制:0.25s空间限制:4MSolution n=10000,m=100000,显然不能用矩阵乘法乘出来。 S= ATA 对于矩阵S的一行,所有在A矩阵中1位置的元素都相等,并且都等于这一行1的个数之和。假设有k个1,这一行的和显然是k*k 由此只要统计每一行有多...
分类:
其他好文 时间:
2014-09-10 19:11:00
阅读次数:
162
Divide Two Integers
Divide
two integers without using multiplication, division and mod operator.
分析:...
分类:
其他好文 时间:
2014-09-09 13:01:42
阅读次数:
164
题目链接题意: 有一个数p=1,甲乙两人轮流操作,每次可以把p乘2~9中的一个数,给定一个n,当一个人操作后p>=n,那么这个人赢,问先手是否必胜。必胜状态:存在一种走法走到一个必败状态。必败状态:后继状态都为必胜状态。我们可以知道>=n的数都为必败状态,可以转移到>=n的最小的数为n/9(上取整)...
分类:
其他好文 时间:
2014-09-08 00:57:26
阅读次数:
397
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega...
分类:
其他好文 时间:
2014-09-05 12:36:41
阅读次数:
227
Divide two integers without using multiplication, division and mod operator.思路:取被除数和除数的绝对值求解即可。不过,需要考虑特殊情况:INT_MIN取绝对值仍然是INT_MIN。 1 class Solution { 2...
分类:
其他好文 时间:
2014-09-04 20:46:30
阅读次数:
214