#include<iostream>
#include<stack>
#include<string>
#include<cctype>
using namespace std;

#define N 30
struct node
{
char m;
int r,c;
} a[N];
string s;

bool process(int& ans)
{
int len,i;
stack<node> sta;
node x,y,t;

len=s.length();
if(len==1)
{
ans=0;
return true;
}
ans=0;
for(i=0;i<len;i++)
if(isupper(s[i]))
sta.push(a[s[i]-'A']);
else if(s[i]==')')
{
x=sta.top();
sta.pop();
y=sta.top();
sta.pop();
if(x.r!=y.c) return false;
t.r=y.r;
t.c=x.c;
ans+=y.r*y.c*x.c;
sta.push(t);
}
return true;
}

int main()
{
int n,i,ans;
char c;

cin>>n;
for(i=0;i<n;i++)
{
getchar();
cin>>c;
a[c-'A'].m=c;
cin>>a[c-'A'].r>>a[c-'A'].c;
}
while(cin>>s)
{
if(!process(ans))
cout<<"error"<<endl;
else
cout<<ans<<endl;
}
return 0;
}

hdu1082的更多相关文章

  1. Matrix Chain Multiplication[HDU1082]

    Matrix Chain Multiplication Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. hdu-1082 Matrix Chain Multiplication---栈的运用

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1082 题目大意: 题意大致是N个矩阵,如果要求计算的矩阵例如(AB),如果A的列等于B的行,进行:A ...

随机推荐

  1. poj 2251 Dungeon Master-搜索进阶-暑假集训

    普及一下知识 s.empty() 如果栈为空返回true,否则返回falses.size() 返回栈中元素的个数s.pop() 删除栈顶元素但不返回其值s.top() 返回栈顶的元素,但不删除该元素s ...

  2. HBase常用操作-HBaseUtil

    package com.zhen.hbase; import java.io.IOException; import java.util.ArrayList; import java.util.Col ...

  3. 【原创】cocos2d-x3.9蓝牙开发之蓝牙开启

    本人第一次搞android开发,很多东西都是只知道一点点,然而都没怎么实践过,所以这次就边学边做自己想要的功能,可能会花较长时间,不过肯定是值得的,有用词或哪里说得不对的请指正. 我自己有androi ...

  4. 英语发音规则---(e)s和-(e)d的读音规则

    英语发音规则---(e)s和-(e)d的读音规则 一.总结 一句话总结: 1.大部分可数名词的复数及动词第三人称单数的一般现在式,是以-(e)s结尾的? moths,glasses:digs,teac ...

  5. hdu3572线性欧拉筛

    用线性筛来筛,复杂度O(n) #include<bits/stdc++.h> #include<ext/rope> #define fi first #define se se ...

  6. 九 Django框架,Form表单验证

    表单提交 html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  7. MVC5中EF6 Code First启动慢及间隙变慢的一些优化处理

    问题描述: 第一次访问的时候很慢,后面再次打开页面很快,过了一段时间不访问页面然后再次打开页面又像第一次那样很慢. 采用的技术和环境: 使用技术:EF6+MVC5 服务器环境:Windows 2012 ...

  8. 属性成员是isXxx时对应的get方式是isXxx,前台jsp取不到这个属性值

    最近在项目中无意设置的boolean变量值为isXxx,用eclipse生成相应的set和get方法,eclipse生成的的boolean类型的get方法为isXxx,前台导致取不到相应的值 publ ...

  9. 【leetcode刷题笔记】Integer to Roman

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  10. bzoj 2002: 弹飞绵羊 Link-Cut-Tree

    题目: Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置, ...