UVA 442(p141)----Matrix Chain Multiplication
来源:互联网 发布:三级域名申请 编辑:程序博客网 时间:2024/05/29 15:13
#include<iostream>#include<cstdio>#include<stack>#include<cstring>#include<algorithm>using namespace std;struct point{ int a,b; point(int x=0,int y=0):a(x),b(y) {}};int n;point m[30];stack<point> s;int main(){ cin>>n; for(int i=0; i<n; i++) { char a; int x,y; cin>>a>>x>>y; int tmp=a-'A'; m[tmp].a=x; m[tmp].b=y; } string st; while(cin>>st) { int l=st.length(); int flag=0,ans=0; for(int i=0; i<l; i++) { if(isalpha(st[i])) s.push(m[st[i]-'A']); else if(st[i]==')') { point x=s.top(); s.pop(); point y=s.top(); s.pop(); if(y.b!=x.a) { flag=1; break; } else { ans+=y.a*y.b*x.b; s.push(point(y.a,x.b)); } } } if(flag) cout<<"error"<<endl; else cout<<ans<<endl; } return 0;}题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=383
0 0
- UVA 442(p141)----Matrix Chain Multiplication
- UVa 442 Matrix Chain Multiplication
- Uva 442 Matrix Chain Multiplication
- UVa 442 Matrix Chain Multiplication
- uva 442 - Matrix Chain Multiplication
- UVa 442 - Matrix Chain Multiplication
- UVa 442 - Matrix Chain Multiplication
- UVa 442 Matrix Chain Multiplication
- UVA 442 Matrix Chain Multiplication
- uva 442 - Matrix Chain Multiplication
- uva 442 Matrix Chain Multiplication
- UVa 442 - Matrix Chain Multiplication
- UVa 442 - Matrix Chain Multiplication
- uva 442Matrix Chain Multiplication
- uva-442 Matrix Chain Multiplication
- UVa 442 - Matrix Chain Multiplication
- uva 442 - Matrix Chain Multiplication
- UVA 442 Matrix Chain Multiplication
- VLC Android播放器介绍
- Android-Adapter实现方法(ArrayAdapter,SimpleAdapter,SimpleCursorAdapter)
- leetcode-94-Binary Tree Inorder Traversal
- lintcode:Remove Node in Binary Search Tree
- 利用php的explode函数将字符串按分隔符(比如空格)分拆并组装在数组中-----要考虑连续空格问题
- UVA 442(p141)----Matrix Chain Multiplication
- HDU 2222 Keyword Search(AC自动机)
- Cpp_类型转换
- HDMI和SDI的简介
- codeforces 589H DFS
- android 自定义TopBar的使用
- 网络---大文件的下载(NSURLConnection)
- 可调用对象
- UVA 455(p57)----Periodic Strings