Uva442 hdu 1082 Matrix Chain Multiplication
要注意取出来的时候 先取出q的是后面那个矩阵 后取出p的是前面的矩阵 所以是判断 p.a == q.b
#include <iostream>
#include <stack>
#include <cstring>
#include <cstdio>
using namespace std;
struct Matrix{
int a,b;
Matrix(,):a(aa),b(bb){}
}m[];
stack<Matrix>s;
int main(){
int n;
scanf("%d",&n);
;i<n;i++){
char t;
cin>>t;
int k=t-'A';
cin>>m[k].a>>m[k].b;
}
string str;
while(cin>>str){
bool error=false;
;
int len=str.length();
;i<len;i++){
if(str[i]=='('){
}
else if(str[i]==')'){
Matrix q=s.top();s.pop();
Matrix p=s.top();s.pop();
if(p.b==q.a){//**
sum+=p.a*p.b*q.b;
s.push( Matrix(p.a,q.b));
}
else {
error=true;
break;
}
}
else{
s.push( m[ str[i]-'A'] );
}
}
if(error){
cout<<"error\n";
}
else{
cout<<sum<<endl;
}
}
;
}
Uva442 hdu 1082 Matrix Chain Multiplication的更多相关文章
- Matrix Chain Multiplication(表达式求值用栈操作)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1082 Matrix Chain Multiplication Time Limit: 2000/100 ...
- UVa442 Matrix Chain Multiplication
// UVa442 Matrix Chain Multiplication // 题意:输入n个矩阵的维度和一些矩阵链乘表达式,输出乘法的次数.假定A和m*n的,B是n*p的,那么AB是m*p的,乘法 ...
- ACM学习历程——UVA442 Matrix Chain Multiplication(栈)
Description Matrix Chain Multiplication Matrix Chain Multiplication Suppose you have to evaluate ...
- Matrix Chain Multiplication[HDU1082]
Matrix Chain Multiplication Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- UVA 442 二十 Matrix Chain Multiplication
Matrix Chain Multiplication Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %l ...
- 例题6-3 Matrix Chain Multiplication ,Uva 442
这个题思路没有任何问题,但还是做了近三个小时,其中2个多小时调试 得到的经验有以下几点: 一定学会调试,掌握输出中间量的技巧,加强gdb调试的学习 有时候代码不对,得到的结果却是对的(之后总结以下常见 ...
- UVa 442 Matrix Chain Multiplication(矩阵链,模拟栈)
意甲冠军 由于矩阵乘法计算链表达的数量,需要的计算 后的电流等于行的矩阵的矩阵的列数 他们乘足够的人才 非法输出error 输入是严格合法的 即使仅仅有两个相乘也会用括号括起来 并且括号中 ...
- UVA——442 Matrix Chain Multiplication
442 Matrix Chain MultiplicationSuppose you have to evaluate an expression like A*B*C*D*E where A,B,C ...
- uva-442 Matrix Chain Multiplication
Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since ma ...
随机推荐
- 【leetcode】Reverse Bits(middle)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【编程题目】输入两个整数 n 和 m,从数列 1,2,3.......n 中 随意取几个数, 使其和等于 m ... ★
第 21 题(数组)2010 年中兴面试题编程求解:输入两个整数 n 和 m,从数列 1,2,3.......n 中 随意取几个数,使其和等于 m ,要求将其中所有的可能组合列出来. 我的思路: 从小 ...
- 【资料】Boost的资料
http://blog.csdn.net/pongba/article/details/1561110
- Keepalived虚拟ip
linux下如何设置vip(虚拟ip) 在做HA的时候需要为服务器设计虚拟IP,也就是一个主机对应多个IP地址?刚听起来好神奇,原来这样也是可能的看了下面的这个链接 自己配了一下http://hi.b ...
- UICollectionView cellForItemAtIndexPath 方法不走
在storyboard 中 UICollectionView cellForItemAtIndexPath not called 被坑了好久,各种问题点查找,终于解决了 解决办法: self.auto ...
- [Android] 关于getinstalledpackages参数的分析
reference to : http://blog.csdn.net/luojiusan520/article/details/47696891 getinstalledpackages()的方法 ...
- ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(二) 之 ChatServer搭建,连接服务器,以及注意事项。
上篇:ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(一) 之 基层数据搭建,让数据活起来(数据获取) 上一篇我们已经完成了初步界面的搭建工作,本篇将介绍IM的核心内容 ...
- python基础——使用模块
python基础——使用模块 Python本身就内置了很多非常有用的模块,只要安装完毕,这些模块就可以立刻使用. 我们以内建的sys模块为例,编写一个hello的模块: #!/usr/bin/env ...
- NYOJ题目1051simone牌文本编辑器
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsgAAAKFCAIAAABeD4iTAAAgAElEQVR4nO3dO3LjOtOA4X8TzrUQx1
- vim 查找时忽略大小写
:set ic 忽略大小写#ignorecase :set noic 不忽略大小写#noignorecase