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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Little Red Riding Hood(动态规划)

發布時間:2023/12/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Little Red Riding Hood(动态规划) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目:

?Little Red Riding Hood

?

題目描述

? ? Once upon a time, there was a little girl. Her name was Little Red Riding Hood. One day, her grandma was ill. Little Red Riding Hood went to visit her. On the way, she met a big wolf. “That's a good idea.”,the big wolf thought. And he said to the Little Red Riding Hood, “Little Red Riding Hood, the flowers are so beautiful. Why not pick some to your grandma?” “Why didn't I think of that? Thank you.” Little Red Riding Hood said.

? ? Then Little Red Riding Hood went to the grove to pick flowers. There were n flowers, each flower had a beauty degree a[i]. These flowers arrayed one by one in a row. The magic was that after Little Red Riding Hood pick a flower, the flowers which were exactly or less than d distances to it are quickly wither and fall, in other words, the beauty degrees of those flowers changed to zero. Little Red Riding Hood was very smart, and soon she took the most beautiful flowers to her grandma’s house, although she didn’t know the big wolf was waiting for her. Do you know the sum of beauty degrees of those flowers which Little Red Riding Hood pick??

輸入

? ? The first line input a positive integer T (1≤T≤100), indicates the number of test cases. Next, each test case occupies two lines. The first line of them input two positive integer n and

k (2 <= n <= 10^5 ) ,1 <= ?k <= n ),?the second line of them input n positive integers a (1<=a <=10^5)

輸出

? ? Each group of outputs occupies one line and there are one number indicates the sum of the largest beauty degrees of flowers Little Red Riding Hood can pick.?

樣例輸入

1 3 1 2 1 3

樣例輸出

5

?

題目描述:

動態規劃題,設dp[i]為到拿取第i個位置的最大價值,推出轉移方程即可。

?

代碼:

#include<stdio.h> #include<string.h> int a,b,aa[100010],c[100010],d[100010],f[100010]; int main() {int i,j,k;int t;scanf("%d",&t);while(t--){scanf("%d%d",&a,&b);memset(aa,0,sizeof(aa));memset(c,0,sizeof(c));memset(d,0,sizeof(d));memset(f,0,sizeof(f));int max = 0,max1 = 0;for(i = 1; i <= a;i ++){scanf("%d",&aa[i]);if(i -b-1 >= 1){if(max < aa[i -b-1]){max = aa[i -b-1];}}c[i] = max;if(i - b >= 1){if(max1 < aa[i - 1]){max1 = aa[i - 1];}}d[i] = max1; // printf("%d %d\n",c[i],d[i]);}f[1] = aa[1];int ma=0,ma1=0;for(i = 1;i <=a;i++){if(i-b-1>=1)if(ma<f[i-b-1])ma = f[i-b-1]; // ma1 = 0; // if(i-b>=1){ // for(j=i;j<i+b;j++) // if(ma1<f[j]) // ma1 = f[j]; // }f[i] = ma+aa[i]>f[i-1]?ma+aa[i]:f[i-1]; // printf("!%d\n",f[i]);}printf("%d\n",f[a]);}return 0; }

?

?

?

?

?

總結

以上是生活随笔為你收集整理的Little Red Riding Hood(动态规划)的全部內容,希望文章能夠幫你解決所遇到的問題。

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