日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 3034 Whac-a-Mole(DP)

發布時間:2025/4/14 编程问答 66 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 3034 Whac-a-Mole(DP) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接?

理解了題意之后,這個題感覺狀態轉移還是挺好想的,實現起來確實有點繁瑣,代碼能力還有待加強,經過很長時間才發現bug。注意坐標可能是負的。

1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 int dp[12][40][41]; 8 bool o[12][41][41]; 9 int n,ans,d; 10 int gcd(int a,int b) 11 { 12 return b == 0?a:gcd(b,a%b); 13 } 14 int fun(int t,int x,int y,int tx,int ty,int ax,int ay) 15 { 16 int temp = 0; 17 while(x != ax||y != ay)//開始這里寫成&& 18 { 19 if(o[t+1][x][y]) 20 temp ++; 21 x += tx; 22 y += ty; 23 } 24 return temp+o[t+1][x][y]; 25 } 26 void judge(int t,int x,int y) 27 { 28 int i,j,g; 29 for(i = x-d;i <= x+d;i ++) 30 { 31 for(j = y-d;j <= y+d;j ++) 32 { 33 if((i-x)*(i-x)+(j-y)*(j-y) > d*d) continue; 34 if(i < 0||j < 0) continue; 35 if(i > n+10||j > n+10) continue; 36 g = gcd(abs(i-x),abs(j-y)); 37 if(g == 0) g = 1; 38 int tx,ty; 39 tx = (i-x)/g; 40 ty = (j-y)/g; 41 dp[t+1][i][j] = max(dp[t+1][i][j],dp[t][x][y]+fun(t,x,y,tx,ty,i,j)); 42 ans = max(dp[t+1][i][j],ans); 43 } 44 } 45 } 46 int main() 47 { 48 int m,i,j,k,y,x,t; 49 while(scanf("%d%d%d",&n,&d,&m)!=EOF) 50 { 51 if(n == 0&&d == 0&&m == 0) break; 52 memset(dp,0,sizeof(dp)); 53 memset(o,0,sizeof(o)); 54 for(i = 1; i <= m; i ++) 55 { 56 scanf("%d%d%d",&x,&y,&t); 57 o[t][x+5][y+5] = 1; 58 } 59 ans = 0; 60 for(i = 0; i <= 10; i ++) 61 { 62 for(j = 0; j < n+10; j ++) 63 { 64 for(k = 0; k < n+10; k ++) 65 { 66 judge(i,j,k); 67 } 68 } 69 } 70 printf("%d\n",ans); 71 } 72 return 0; 73 }

?

轉載于:https://www.cnblogs.com/naix-x/p/3188582.html

總結

以上是生活随笔為你收集整理的POJ 3034 Whac-a-Mole(DP)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。