额,出了一题,一题被system test搞掉了,今天一看,尼玛脑残了,不能理解为什么第二题想成是dp了。。。
好吧
A题,没什么说的,排个序然后随便dp下就可以了,因为排序之后选择了起点和终点tone之差的这些数的和就是定的了。。
#include <algorithm> #include <vector> using namespace std; typedef struct { int d,t; }Song; bool cmp(Song x,Song y) { if (x.t!=y.t) return x.t<y.t; return x.d<y.d; } bool cmp1(Song x,Song y) { if (x.d!=y.d) return x.d<y.d; return x.t<y.t; } class GUMIAndSongsDiv1 { public: Song a[55]; Song b[55]; int maxSongs(vector <int> duration, vector <int> tone, int T) { int i,j,k,n; n=duration.size(); for (i=0;i<n;i++) { a[i].d=duration[i]; a[i].t=tone[i]; b[i]=a[i]; } sort(a,a+n,cmp); sort(b,b+n,cmp1); int ans=0; for (i=0;i<n;i++) { for (j=i;j<n;j++) { int cnt=0,t; t=a[j].t-a[i].t; for (k=0;k<n;k++) { if (b[k].t>=a[i].t && b[k].t<=a[j].t) { if (b[k].d+t>T) continue; cnt++; t+=b[k].d; } } ans=max(ans,cnt); } } return int(ans) ; } };
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <vector> using namespace std ; #define For(i , n) for(int i = 0 ; i < (n) ; ++i) #define SZ(x) (int)((x).size()) typedef long long lint ; const int maxint = -1u>>2 ; const double eps = 1e-6 ; typedef struct { int r,g,w,state; }Key; queue<Key> q; int vis[(1<<12)+5][125]; class KeyDungeonDiv1 { public: int maxKeys(vector <int> doorR, vector <int> doorG, vector <int> roomR, vector <int> roomG, vector <int> roomW, vector <int> keys) { int i,j,n,ans; n=doorR.size(); memset(vis,0,sizeof(vis)); Key tmp; tmp.r=keys[0]; tmp.g=keys[1]; tmp.w=keys[2]; tmp.state=0; q.push(tmp); ans=0; while(!q.empty()) { tmp=q.front(); q.pop(); if (vis[tmp.state][tmp.r]==1) continue; vis[tmp.state][tmp.r]=1; ans=max(ans,tmp.g+tmp.w+tmp.r); i=tmp.state; for (j=0;j<n;j++) { if ((i & (1<<j))!=0) continue; int lr=max(0,doorR[j]-tmp.r); int lg=max(0,doorG[j]-tmp.g); // printf("%d %d %d %d\n",i,j,doorR[j],dp[i].r); if (lr+lg>tmp.w) continue; Key tmp1; tmp1.r=max(0,tmp.r-doorR[j])+roomR[j]; tmp1.g=max(0,tmp.g-doorG[j])+roomG[j]; tmp1.w=tmp.w-(lr+lg)+roomW[j]; int p=(i | (1<<j)); tmp1.state=p; q.push(tmp1); } } return int(ans); } };