Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助:为什么总是WR啊?#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int big; int s[11][2500]; bool b[2500][2500]; struct Book { int v; char re[32]; char ch[32]; }book[2501]; struct Name { char c[35]; } name[11]; bool bb(Book b1,Book b2) { return strcmp(b1.ch,b2.ch)<0; } bool cmp(Name a,Name b) { return strcmp(a.c,b.c)<0; } inline void change(char a[],char b[]) { int i=0,k=0; while(a[i]){ if(a[i]>='a'&&a[i]<='z'||a[i]>='A'&&a[i]<='Z'){ b[k]=a[i]; k++; } i++; } b[k]='\0'; } inline bool ok(char a[],char b[]) { int i=0; while(a[i]&&b[i]&&toupper(a[i])!=toupper(b[i]))i++; if(a[i]&&b[i])return 0; return 1; } void dfs(int le,int ma,int c[],int n) { int i; if(le==0)return ; for(i=n;i>=0;--i){ if(s[le][i]==ma){ c[le]=i; dfs(le-1,ma-book[i].v,c,n); return ; } } big=le-1; dfs(le-1,ma,c,n); } int main() { int i,n,j,k; char c; scanf("%d",&n); { for(i=0;i<n;++i){ scanf("%d%c",&book[i].v,&c); int j=0; while(scanf("%c",&c),c!='\n'){ book[i].re[j]=c; j++; } book[i].re[j]='\0'; } for(i=0;i<n;++i){ change(book[i].re,book[i].ch); } sort(book,book+n,bb); for(i=0;i<n;++i){ for(j=i+1;j<n;++j){ if(ok(book[i].ch,book[j].ch)){ b[i][j]=1; } else b[i][j]=0; } } int maxx=0; for(i=1;i<=10;++i){ for(j=0;j<n;++j) s[i][j]=-1; } for(i=0;i<n;++i){ s[1][i]=book[i].v; if(maxx<s[1][i])maxx=s[1][i]; } for(i=2;i<=10;++i){ for(j=i-1;j<n;++j){ for(k=i-2;k<j;++k){ if(s[i-1][k]!=-1&&b[k][j]&&s[i-1][k]+book[j].v>s[i][j]){ s[i][j]=s[i-1][k]+book[j].v; if(maxx<s[i][j])maxx=s[i][j]; } } } } big=10; int c[11]; dfs(10,maxx,c,n); printf("%d\n",big); printf("%d\n",maxx); for(i=1;i<=big;++i){ strcpy(name[i-1].c,book[c[i]].re); } sort(name,name+big,cmp); for(i=1;i<=big;++i){ printf("%s\n",book[c[i]].re); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator