惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
雷峰网
雷峰网
博客园 - 叶小钗
V
V2EX
博客园 - Franky
博客园_首页
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
S
SegmentFault 最新的问题
B
Blog RSS Feed
博客园 - 【当耐特】
D
Docker
N
Netflix TechBlog - Medium

博客园 - saintqdd

hdu 1102 pku 2421 解题报告 pku 2777 Count Color 解体报告 石子合并问题 nkoj1139和乘积最大那题一样. 最大黑区域 滑雪 一道经典题,humble number 今天碰到了一个很诡异的题,Alphacode (zoj 2202) 这两天经常碰到dp题,就写了一个0-1背包 实训以来,到这里的次数少了! 郁闷,乘积最大那题WA原来只是因为我用了pow函数引起的! Smith Number POJ强烈推荐50题 JOJ 2391 words POJ 1014 三十分钟掌握STL STL学习小记 POJ1006,中国剩余定理 POJ1003,简单题
A Tour in Loquat Orchard (FZU 2007 ICPC Qualification Ro...
saintqdd · 2007-09-01 · via 博客园 - saintqdd

相当经典的动归.

#include<stdio.h>
const int MAX=100001;
int f[MAX];
struct{
  int z,y;
}arr[2*MAX];
int main(){
  int N,n,i,j,max,num;
  while(scanf("%d",&N)!=-1){
    i=1;
    while(i<=N){
      scanf("%d",&f[i++]);
    }
    scanf("%d",&n);
    i=0;
    while(i<n){
      scanf("%d %d",&arr[i].z,&arr[i].y);
      i++;
    }
    num=0;
    for(i=n-1;i>=0;){
       max=0;
       for(j=i;j>=0&&arr[j].z==arr[i].z;j--){
         if(f[arr[j].y]>max)
           max=f[arr[j].y];
       }
       f[arr[i].z]+=max;
       if(f[arr[i].z]>num)
         num=f[arr[i].z];
       i=j;
    }
    printf("%d"n",num);
  }
}