标签:输入 while 技术 otto class main memset include alt
Description
Input
Output
Sample Input
Sample Output
二维数组的dp问题。
//Asimple #include<iostream> #include<cstring> using namespace std; int maxi(int a,int b,int c) { int max1; max1=a>b?a:b; max1=max1>c?max1:c; return max1; } int c[100001][11]; int main() { int i,j; int n,a,b; while(cin>>n&&n) { int m=0; memset(c,0,sizeof(c)); for(i=0;i<n;i++) { cin>>a>>b; c[b][a]++; if(m<b) m=b; } for(i=m-1;i>=0;i--) { for(j=1;j<=9;j++) c[i][j]+=maxi(c[i+1][j-1],c[i+1][j],c[i+1][j+1]); c[i][0]+=max(c[i+1][0],c[i+1][1]); c[i][10]+=max(c[i+1][10],c[i+1][9]); } cout<<c[0][5]<<endl; } return 0; }
标签:输入 while 技术 otto class main memset include alt
原文地址:http://www.cnblogs.com/Asimple/p/6107533.html