An old Stone Game ~~GarsiaWachs算法
来源:互联网 发布:mac pro retina 编辑:程序博客网 时间:2024/05/17 23:11
/*******************author:YKYemail:191217500@qq.comlanguage:c++problem:GarsiaWachs*******************/ #include<iostream> #include<stdio.h>#define maxx 50000using namespace std;int stone[maxx],n,t;int ret;void combine(int k){int tmp=stone[k]+stone[k-1];ret+=tmp;for(int i=k;i<t-1;i++)stone[i]=stone[i+1];t--;int j;for(j=k-1;j>0 && stone[j-1]<tmp;j--)stone[j]=stone[j-1];stone[j]=tmp;while(j>=2 && stone[j]>=stone[j-2]){int d=t-j;combine(j-1);j=t-d;} }int main(){while(scanf("%d",&n),n){for(int i=0;i<n;i++)scanf("%d",&stone[i]);t=1,ret=0;for(int i=1;i<n;i++){stone[t++]=stone[i];while(t>=3 && stone[t-3]<=stone[t-1])combine(t-2);}while(t>1) combine(t-1);printf("%d\n",ret);}return 0; }
- An old Stone Game ~~GarsiaWachs算法
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- POJ 1738:An old Stone Game 石子归并(GarsiaWachs算法)
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- POJ 1738 An old Stone Game 石子合并之GarsiaWachs算法
- poj 1738 An old Stone Game(此题数小则可用区间DP,数较大用一维数组或者GarsiaWachs算法),待续
- [GarsiaWachs算法] BZOJ 3229 [Sdoi2008]石子合并 & POJ 1738 An old Stone Game & 51Nod 1023 石子归并 V3
- 1694 An Old Stone Game
- POJ1694 An Old Stone Game
- POJ 1694 An Old Stone Game
- POJ1694 An Old Stone Game (树,排序) .
- ZOJ1427 POJ1694 An Old Stone Game
- POJ 1694 An Old Stone Game
- POJ--1694--An Old Stone Game
- poj 1694 An old stone game
- 北大oj 1694 An Old Stone Game
- POJ 1694 An Old Stone Game 笔记
- java操作文件工具类
- 如果更改SimpleButton 按钮中的文本
- wget命令详解
- 小创新,不同业务场景使用不同的map
- 学科前沿技术(人工智能与智能系统中的先驱人物)
- An old Stone Game ~~GarsiaWachs算法
- Ubuntu下解压rar文件的方法
- 变态问题之禁用C部分关键字
- Adding an Easy Share Action 添加一个简单的共享行动
- apache 实现url 重写
- 设置超链接
- 25条提高iOS App性能的建议和技巧
- Taking Photos Simply 简单地拍摄照片
- VB ListView控件各种操作详解