383
这题其实认真看一下应该会发现是最长上升序列,这题类似与矩形嵌套那题,明白这个做起来就真的很简单了,所以这题算法上真的没得讲,关键你得看得出来是叫你求数对的最长上升序列,时间复杂度为O(k*k);最后稍微注意一下处理四舍五入
AC代码:
# include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <algorithm> using namespace std; struct seg{ int x; int y; }; seg s[1010]; int dp[1010]; int compare(seg a, seg b){ if(a.x!=b.x){ return a.x<b.x; } return a.y<b.y; } int main(){ int n, m, k, i, j, Max; double ans; while(scanf("%d%d%d", &n, &m, &k)!=EOF){ for(i=1; i<=k; i++){ dp[i]=1; } Max=-1; dp[1]=1; for(i=1; i<=k; i++){ scanf("%d%d", &s[i].x, &s[i].y); } sort(s+1, s+k+1, compare); for(i=2; i<=k; i++){ for(j=1; j<i; j++){ if(s[i].x>s[j].x&&s[i].y>s[j].y){ dp[i]=max(dp[j]+1, dp[i]); } } Max=max(Max, dp[i]); } ans=(m+n-Max*2)*100+100.0*sqrt(2.0)*Max; int c=(int)(ans*10)-(int)ans*10; if(c<=4){ printf("%d\n", (int)ans); } else{ printf("%d\n", (int)ans+1); } } return 0; }