Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place:

  • A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars.
  • Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.

Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally.

Input

The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000).

Output

Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.

Example

Input
7
win 10
win 5
win 3
sell 5
sell 3
win 10
sell 10
Output
1056
Input
3
win 5
sell 6
sell 4
Output
0

题目分析 : 一个人卖内存条,sell 表示有人去买此内存条, win表示获取到此内存条,这个人最多只能拥有一个内存条,并且同时也保证买不同型号内存条的只会有一个顾客,问此人能获得的最大收益。
思路分析 : 输出答案得是高精度,选购物品的时候贪心的去选, 因为 2^5 一定大于 2^1 + 2^2 + 2^3 + 2^4。
代码示例 :
#define ll long long
const int maxn = 1e6+5;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f; int n;
struct node
{
int state, x; // 1 是 win, 0 是 sell
int pt; // 1 是存在
}pre[5005];
vector<int>f[2005];
int p[2005];
vector<int>ans, mid; void init() {
f[0].push_back(1); for(int i = 1; i <= 2000; i++){
f[i].assign(f[i-1].size(), 0);
for(int j = 0; j < f[i].size(); j++){
f[i][j] = f[i-1][j] + f[i-1][j];
}
for(int j = f[i].size()-1; j >= 0; j--){
if (f[i][j] > 9){
f[i][j] -= 10;
if (j != 0) f[i][j-1]++;
else f[i].insert(f[i].begin(), 1);
}
}
}
} void bigsum(int x){
mid.clear();
mid.assign(ans.size(), 0); for(int i = ans.size()-1, j = f[x].size()-1; i >= 0; ){
if (j >= 0){
mid[i] = ans[i] + f[x][j];
i--, j--;
}
else {mid[i] = ans[i]; i--;}
} for(int i = mid.size()-1; i >= 0; i--){
if (mid[i] > 9){
mid[i] -= 10;
if (i != 0) mid[i-1]++;
else mid.insert(mid.begin(), 1);
}
}
ans = mid;
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n;
char s[10];
int x; init();
for(int i = 1; i <= n; i++) {
scanf("%s%d", s, &x);
if (s[0] == 'w') pre[i].state = 1;
else {
pre[i].state = 0;
p[x] = i;
}
pre[i].x = x; pre[i].pt = 1;
} int sign = 1;
for(int i = 2000; i >= 0; i--){
if (!p[i]) continue;
int pos = 999999;
for(int j = p[i]-1; j >= 1; j--){
if (pre[j].pt == 0) break;
if (pre[j].state == 1 && pre[j].x == i){
pos = j;
if (sign) {ans = f[i]; sign = 0;}
else bigsum(i);
break; }
}
for(int j = p[i]; j >= pos; j--){
if (pre[j].state == 0) p[pre[j].x] = 0;
else pre[j].pt = 0;
}
//printf("----- %d %d\n", i, pos);
}
if (sign) {printf("0\n"); return 0;}
for(int i = 0; i < ans.size(); i++){
printf("%d", ans[i]);
}
printf("\n");
//puts("");
return 0;
}
 

CF - 高精度 + 贪心的更多相关文章

  1. CF/div2c/贪心

    题目链接[http://codeforces.com/contest/749/problem/C] 题意:给出一个长度为n序列包含D和R,每一轮操作的先后顺序是1-n,规则是每一轮每个人有一次机会杀掉 ...

  2. *cf.4 贪心

    D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  3. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  4. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  5. 【Noip2012】解题报告【字符】【贪心】【高精度】【倍增】【set】

    目录:1:vigenere密码[字符]2:国王游戏[贪心][高精度]3:开车旅行[倍增][set] 题目: VJ P1778   vigenere密码 Accepted 标签:NOIP提高组2012 ...

  6. POJ 2325 Persistent Numbers#贪心+高精度除法

    (- ̄▽ ̄)-* 这道题涉及高精度除法,模板如下: ]; ];//存储进行高精度除法的数据 bool bignum_div(int x) { ,num=; ;s[i];i++) { num=num*+ ...

  7. P1080 国王游戏 贪心 高精度

    题目描述 恰逢 HH国国庆,国王邀请nn 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 nn 位大臣排成一排,国王站在队伍的 ...

  8. luogu1080 国王游戏(贪心+高精度)

    貌似这道题是碰巧蒙对了贪心的方式..就是把ai*bi越小的放在越前面 (不过也符合直觉) 然后统计答案需要用高精度,然后就调了一年 #include<cstdio> #include< ...

  9. Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)

    Luogu 1080 [NOIP2012]国王游戏 (贪心,高精度) Description 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己 ...

随机推荐

  1. H3C 多区域OSPF配置示例

  2. H3C 显示RIP当前运行状态及配置信息

  3. 对input输入框日期显示格式化

    先:导入fmt标签 在对input框进行属性设置 <input type="text" name="createtime"  value="&l ...

  4. C# 循环的判断会进来几次

    最近有小伙伴告诉我,在循环的判断条件只会计算一次,本金鱼不相信,于是就做了测试,本文记录我做的测试. 先来写一个简单的代码, 就一个循环,循环的判断是从一个函数获取值 class Program { ...

  5. dotnet 删除只读文件

    如果直接通过 File.Delete 删除只读文件会出现没有权限提示,可以先设置文件不是只读然后删除文件 try { File.Delete(file); } catch (UnauthorizedA ...

  6. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  7. CITRIX ADC配置SSL卸载

    如上图,将ssl的加密解密放在前端的负载均衡设备上,客户端到VPX的访问都是加密的,VPX到后端的服务器都是http的 Step1:上传证书到VPX,如下图: Step2:创建SSL的虚拟服务器并且绑 ...

  8. 关于instanface的问题

    nstanceof关键字来判断某个对象是否属于某种数据类型.报错  代码如下 package cn.lijun.demo3; import cn.lijun.demo.Person;import cn ...

  9. MySQL Server逻辑架构

    1.MySQL基础 MySQL是一个开放源代码的关系数据库管理系统.原开发者为瑞典的MySQL AB公司,最早是在2001年MySQL3.23进入到管理员的视野并在之后获得广泛的应用. 2008年My ...

  10. 第二阶段:2.商业需求分析及BRD:2.产品需求池

    需求获取方式 比如公司战略方面的需求  用户的反馈:投诉 建议等等 产品经理需要时刻关注竞品以及行业的发展! 需求池:各个产品经理的需求总和成一个需求池.让资源更好的利用起来.有的公司还有个“需求管理 ...