不充钱,你怎么AC?

  题目:http://codevs.cn/problem/1166/

  有许久没有刷题了,忙着过中秋去了嘿嘿

  首先它的每一行是独立的,我们可以直接把它拆分成 n 互不相关的子问题做

  那么就变成了区间 DP 问题,f[i][j] 表示在区间 [i,j] 内的最大分数,首先枚举区间长度 k,然后再枚举左端点 i

    

  n 表示的是一行数的个数

  注意 k 要到-1,是因为 f[i][i] 时还有一个 a[i] 没有取走,目标状态是 max ( f[i][i-1] ) ,(i=1~n)

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define N 90
using namespace std; long long a[N],f[N][N],m,ans,t,n;
int main()
{
long long i,k;
cin>>t>>n;
while (t>)
{
t--;
for (i=;i<=n;i++) cin>>a[i];
for (k=n-;k>=-;k--)
{
for (i=;i<=n-k;i++)
{
f[i][i+k]=max(f[i-][i+k]+a[i-]*(<<(n-k-)),f[i][i+k+]+a[i+k+]*(<<(n-k-)));
}
}
m=;
for (i=;i<=n;i++) m=max(m,f[i][i-]);
ans+=m;
}
cout<<ans<<endl;
return ;
}

  这段代码交上去只有60分,是为什么呢?

  查了很久的问题,结果返回一看题目数据范围,要写高精度……当年应该觉得这道题太简单了,于是就放个高精度卡掉选手40分

  那么就写一个高精度的加法和比较大小即可,直接贴别人的代码嘿嘿

 #include<cstdio>
#include<cstring>
#include<iostream>
#define maxn 100
#define base 10000
using namespace std; int n,m,cnt=,lp[],rp[];
int map[][];
struct Bign
{
int c[maxn],len;
Bign ()
{
memset(c,,sizeof(c)),len=;
}
void Zero()
{
while(len>&&c[len]==)len--;
}
void Write(char *s)
{
int l=strlen(s);
int k=;
for(int i=l-;i>=;i--)
{
c[len]+=k*(s[i]-'');
k*=;
if(k==base)
{
k=;len++;
}
}
}
void Read()
{
char s[maxn];
scanf("%s",s);
Write(s);
}
void Print()
{
printf("%d",c[len]);
for(int i=len-;i>=;i--) printf("%04d",c[i]);
printf("\n");
}
Bign operator = (const int &a)
{
memset(c,,sizeof(c));
len=;
char s[maxn];
sprintf(s,"%d",a);
Write(s);
Zero();
return *this;
}
Bign operator +(const Bign &a)
{
Bign r;
r.len=max(len,a.len)+;
for(int i=;i<=r.len;i++)
{
r.c[i]+=c[i]+a.c[i];
r.c[i+]+=r.c[i]/base;
r.c[i]%=base;
}
r.Zero();
return r;
}
Bign operator +(const int &a)
{
Bign b;
b=a;
return *this+b;
}
Bign operator *(const Bign &a)
{
Bign r;
r.len=len+a.len+;
for(int i=;i<=len;i++)
{
for(int j=;j<=a.len;j++)
{
r.c[i+j-]+=c[i]*a.c[j];
}
}
for(int i=;i<=r.len;i++)
{
r.c[i+]+=r.c[i]/base;
r.c[i]%=base;
}
r.Zero();
return r;
}
Bign operator *(const int &a)
{
Bign b;
b=a;
return *this*b;
}
bool operator < (const Bign &b)const
{
if(len!=b.len) return len<b.len;
else
{
for(int i=len;i>=;i--)
{
if(c[i]!=b.c[i]) return c[i]<b.c[i];
}
}
return ;
}
bool operator >(const Bign &b)const
{
return b<*this;
}
bool operator <=(const Bign &b)const
{
return !(b>*this);
}
bool operator >=(const Bign &b)const
{
return !(b<*this);
}
bool operator == (int a)
{
return len== && c[len]==a;
}
};
Bign f[][];
Bign Max(Bign a,Bign b)
{
if(a>=b) return a;
if(a<b) return b;
}
int main()
{
Bign ans;
ans=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%d",&map[i][j]);
}
}
for (int i=;i<=n;i++)
{
for(int u=;u<=m;u++)
for(int v=;v<=m;v++) f[v][u]=;
for (int j=;j<=m;j++)
{
f[j][j]=map[i][j]*;
}
for(int len=;len<=m-;len++)
{
for(int l=;l<=m&&l+len<=m;l++)
{
Bign k;
k=max(f[l+][l+len]+map[i][l],f[l][l+len-]+map[i][l+len]);
f[l][l+len]=k*;
}
}
ans=ans+f[][m];
}
ans.Print() ;
return ;
}

[ CodeVS冲杯之路 ] P1166的更多相关文章

  1. [ CodeVS冲杯之路 ] P1368

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1368/ 嗯……泡泡堂,很劲啊,其实就是个盗版的田忌赛马 http://www.cnblogs.com/hyfer/p/ ...

  2. [ CodeVS冲杯之路 ] P1092

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1092/ 嗯,这道题有一定难度啊,需要先用扩展欧几里得算法求出逆元,然后按照大小构一颗带边权为小时数的树 树链剖分后在树 ...

  3. [ CodeVS冲杯之路 ] P3955

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/3955/ 最长上升子序列的加强版,n 有1000000,n 方的 DP 肯定会 TLE,那么用二分栈维护 二分栈我讲不好 ...

  4. [ CodeVS冲杯之路 ] P1165

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1165/ 题目很简单,代码最好写朴实一点,不要想着哪些情况可以合并在一起啊等等 老老实实一个个判断,不然很容易出错 细节 ...

  5. [ CodeVS冲杯之路 ] P1053

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1053/ 直接扫一遍串,把字母对应的 ascii 码直接做数组下标,交给数组统计 最后查询一遍数组的 'a'-'z' , ...

  6. [ CodeVS冲杯之路 ] P1171

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1171/ 代码调了很久才调好啊,一开始题目都看错了(要是真的NOIP肯定没戏了QuQ) 后面发现CodeVS上的数据输入 ...

  7. [ CodeVS冲杯之路 ] P1197

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1197/ 密钥的字母可以全转换为小写字母,然后一一映射,a→0,b→1,c→2,依此类推 对于密文只需将每一位减去对应密 ...

  8. [ CodeVS冲杯之路 ] P2492

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/2492/ 在此先orz小胖子,教我怎么路径压缩链表,那么这样就可以在任意节点跳进链表啦(手动@LCF) 对于查询操作,直 ...

  9. [ CodeVS冲杯之路 ] P2456

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/2456/ 用贪心的思想,木材当然要尽量分成多的木板,而大的木材能够分成大木板,但是小的木材不一定能够分成大的木板,所以木 ...

随机推荐

  1. <Docker学习>6. docker使用网络

    在容器中部署一个web应用,外部如何访问? 容器与容器间如何访问? 外部访问容器 容器可以运行一些网络应用,让外部也可以访问的话,需要进行服务器和容器的端口映射 -p 或者 -P -P默认会分配一个4 ...

  2. Mysql 索引 简介

    Mysql索引 索引的分类 索引的创建 索引的注意事项 什么是索引 索引是存储引擎用于快速查找记录的一种数据结构. 索引由数据库中一列或者多列组成,作用是提高表的查询速度. 索引的优点,提高检索数据的 ...

  3. C++基础 inline 默认参数 函数占位参数 函数重载

    1. inline内联函数 内联函数用于替换宏, 实例: 其中宏和 ++ 连用有副作用. #include "iostream" using namespace std; #def ...

  4. [BZOJ3172 ][Tjoi2013]单词(AC自动机)

    Description 不稳定的传送门 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次.单词个数<=200,单词总长度< ...

  5. [Codeforces958F2]Lightsabers (medium)(思维)

    Description 题目链接 Solution 设一个l指针指向当前数列左边,从左往右扫描一遍,将当前颜色记录, 当所有颜色都得到后,进行判断,如果当前l指向的颜色大于需要的颜色,l后移一位,然后 ...

  6. 十二、mysql之视图,触发器,事务等

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  7. Android开发——View滑动冲突解决方案

    0. 前言   我们在Android开发--事件分发机制详解中深入学习了事件分发机制,为我们解决Android开发中的滑动冲突问题做了初步准备.针对滑动冲突这里给出两种解决方案:外部拦截法和内部拦截法 ...

  8. Quartus 11进行编译Compile Design的时候出现错误near text ã

    1. 设计的工程在Compile Design的时候出现以下的错误,百思不得姐 Error (): Verilog HDL syntax error at div_5.v() near text ã ...

  9. css一些事儿

    1. margin和padding 如果边界画一条线,则margin的属于边界外,padding属于边界内 当我们给元素背景色时,margin区域不会被着色,而padding区域会被着色. 当上下两个 ...

  10. visio2013密钥

    66DNF-28W69-W4PPV-W3VYT-TJDBQ http://www.xiazaizhijia.com/rjjc/133264.html