不充钱,你怎么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. ubuntu安装tomcat7

    1. 下载apache-tomcat-7.0.64.tar.gz 进入tomcat官网:http://tomcat.apache.org/download-70.cgi下载相应的压缩包: 2. 上传安 ...

  2. C语言进阶——const 和 volatile 分析09

    const只读变量: const修饰的变量是只读的,本质还是一个变量 const修饰的局部变量在栈上分配空间 const修饰的全局变量在全局函数区分配资源空间 const只在编译器有用,在运行期无用 ...

  3. JAVA-数组或集合

    哈哈,今天我们来讲解一下有关于一些数组 或者是集合的知识点 1.ArrayList,LinkedList,Vector的区别 ArrayList,LinkedList,Vector都是实现List接口 ...

  4. SpringMVC---web.xml配置详解

    web.xml中需要配置的内容 1.配置监听器<listener> 它有两个监听器: 1). <!--配置文件加载监听器--> <listener> <lis ...

  5. laravel - ReflectionException in Container.php, Class not found?

    SIGN UPSIGN IN CATALOG SERIES PODCAST DISCUSSIONS ReflectionException in Container.php, Class not fo ...

  6. IOS客户端的个人中心可以查看自己的博客了。

    IOS客户端的个人中心可以查看自己的博客了. 写这篇是为了在客户端显示之用. 下一步实现在客户端发博客.

  7. 《Cracking the Coding Interview》——第11章:排序和搜索——题目7

    2014-03-21 22:05 题目:给你N个盒子堆成一座塔,要求下面盒子的长和宽都要严格大于上面的.问最多能堆多少个盒子? 解法1:O(n^2)的动态规划解决.其实是最长递增子序列问题,所以也可以 ...

  8. Django笔记 —— 入门简介

    最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...

  9. Javascript在浏览器中的加载顺序详解!

    现在前端用javascript用的比较多,当然真心的说这个语言是一个非常业余的语言,但是用的人很多,所以也比较火.今天想完成一个javascript外部文件自动加载的设计(类似于java或者php的i ...

  10. Kd-Tree&Ransac笔记

    关于sift资源总结: http://blog.csdn.net/masibuaa/article/details/9191309 两个比较好的资源: https://my.oschina.net/k ...