HDU 1078 Fatmouse and Cheese

Source: Internet
Author: User

Recently do the topic is basically 1A ah, in the end is still due to hit the code before the implementation of the details are to think clearly, and not as before there is a general idea began to write, the results while writing also want to think of ideas, like often make the program out of the odds of the bug greatly increased. In the future, the way to write code is to continue.

The idea of solving the problem is in the comments

/* Sort the points, enumerate the points in this order if the k>100 is not, it will time out, here k<100, just 1000000 of the complexity here the next point must be larger than the previous dot actually simplifies the problem, otherwise the enumeration order at all do not know how to design, add this condition, Each point will be used in a state that has already been calculated. */#include <stdio.h> #include <algorithm> #include <string.h>using namespace std; struct Node{int i,j,val;//represents a matrix or i,j is better, with X, Y easily and in the computational geometry of x, y mix}p[10005];int n,k;int a[105][105],dp[105][105];int cmp ( Node A,node b) {return a.val<b.val;} void Init () {memset (dp,-1,sizeof (DP));DP [0][0]=a[0][0];} int main () {#ifndef online_judgefreopen ("In.txt", "R", stdin), #endifwhile (scanf ("%d%d", &n,&k),n!=-1& &k!=-1) {int l=0;for (int i=0;i<n;i++) {for (int j=0;j<n;j++) {scanf ("%d", &a[i][j]);p [l].i=i;p[l].j=j;p[ L++].VAL=A[I][J];}} Init (); sort (p,p+l,cmp); for (int i=0;i<l;i++) {for (int dj=p[i].j-k;dj<=p[i].j+k;dj++) {if (0&LT;=DJ&AMP;&AMP;DJ <n&&a[p[i].i][dj]<p[i].val&&dp[p[i].i][dj]!=-1) {Dp[p[i].i][p[i].j]=max (DP[P[I].I][P[I].J ],DP[P[I].I][DJ]+A[P[I].I][P[I].J]);}} for (int di=p[i].i-k;di<=p[i].i+k;di++) {if (0<=di&&di<n&Amp;&a[di][p[i].j]<p[i].val&&dp[di][p[i].j]!=-1) {Dp[p[i].i][p[i].j]=max (dp[p[i].i][p[i].j],dp[ DI][P[I].J]+A[P[I].I][P[I].J]);}}} int ans=0;for (int i=0;i<n;i++) {for (int j=0;j<n;j++) {Ans=max (ans,dp[i][j]);}} printf ("%d\n", ans);}}


HDU 1078 Fatmouse and Cheese

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.