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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

汉子编码比字母编码长_字母/博客作者编码问题(使用动态编程)

發布時間:2025/3/11 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 汉子编码比字母编码长_字母/博客作者编码问题(使用动态编程) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

漢子編碼比字母編碼長

Problem statement:

問題陳述:

Shivang is a blog writer and he is working on two websites simultaneously. He has to write two types of blogs which are:

Shivang是一位博客作家,他同時在兩個網站上工作。 他必須寫兩種類型的博客:

  • Technical blogs for website_1: X of this type can be written in an hour. (X will be the input)

    website_1的技術博客 :此類X可以在一小時內編寫。 ( X將作為輸入)

  • Fun blogs for website_2: Y of this type can be written in an hour. (Y will be input)

    網站_2的趣味博客 :可以在一個小時內編寫此類Y。 (將輸入Y )

You are to help him to save time. Given N number of total blogs, print the minimum number of hours he needs to put for combination of both the blogs, so that no time is wasted.

您是要幫助他節省時間。 給定總數為N的博客,請打印他將兩個博客組合在一起所需最少小時數 ,以免浪費時間。

Input:N: number of total blogsX: number of Technical blogs for website_1 per hourY: number of Fun blogs for website_2 per hourOutput:Print the minimum number of hours Shivang needs to write the combination of both the blogs (total N). If it is NOT possible, print "?1".

Example:

例:

Input:N: 33X: 12Y: 10Output:-1 Input:N: 36X: 10Y: 2Output:6 (10*3+2*3)

Explanation:

說明:

For the first case,No combination is possible that's why output is -1.For the second test case,Possible combinations are 30 technical blogs (3 hours) + 6 fun blogs (3 hours)20 technical blogs (2 hours) + 16 fun blogs (8 hours)10 technical blogs (1 hours) + 26 fun blogs (13 hours)0 technical blogs (0 hours) + 36 fun blogs (18 hours)So, best combination is the first one which takes total 6 hours

The problem is basically solving equation,

問題基本上是解決方程式,

aX + bY = N where we need to find the valid integer coefficients of X and Y. Return a+b if there exists such else return -1.

aX + bY = N ,我們需要找到XY的有效整數系數。 如果存在則返回a + b ,否則返回-1

We can find a recursive function for the same too,

我們也可以找到相同的遞歸函數,

Say,

說,

f(n) = minimum hours for n problemsf(n) = min(f(n-x) + f(n-y)) if f(n-x), f(n-y) is solved already

We can convert the above recursion to DP.

我們可以將上述遞歸轉換為DP。

Solution Approach:

解決方法:

Converting the recursion into DP:

將遞歸轉換為DP:

1) Create DP[n] to store sub problem results2) Initiate the DP with -1 except DP[0], DP[0]=03) Now in this step we would compute values for DP[i]4) for i=1 to nif i-x>=0 && we already have solution for i-x,i.e.,DP[i-x]!=-1 DP[i]=DP[i-x]+1;end ifif i-y>=0 && we already have solution for i-y,i.e.,DP[i-y]!=-1)if DP[i]!=-1DP[i]=min(DP[i],DP[i-y]+1);elseDP[i]=DP[i-y]+1;End ifEnd ifEnd for5) Return DP[n]

C++ Implementation:

C ++實現:

#include <bits/stdc++.h> using namespace std;int minimumHour(int n, int x, int y) {int a[n + 1];a[0] = 0;for (int i = 1; i <= n; i++)a[i] = -1;for (int i = 1; i <= n; i++) {if (i - x >= 0 && a[i - x] != -1) {a[i] = a[i - x] + 1;}if (i - y >= 0 && a[i - y] != -1) {if (a[i] != -1)a[i] = min(a[i], a[i - y] + 1);elsea[i] = a[i - y] + 1;}}return a[n]; }int main() {int n, x, y;cout << "Enter total number of blogs, N:\n";cin >> n;cout << "Enter number of techical blogs, X:\n";cin >> x;cout << "Enter number of fun blogs, Y:\n";cin >> y;cout << "Minimum hour to be dedicated: " << minimumHour(n, x, y) << endl;return 0; }

Output

輸出量

RUN 1: Enter total number of blogs, N: 36 Enter number of techical blogs, X: 10 Enter number of fun blogs, Y: 2 Minimum hour to be dedicated: 6RUN 2: Enter total number of blogs, N: 33 Enter number of techical blogs, X: 12 Enter number of fun blogs, Y: 10 Minimum hour to be dedicated: -1

翻譯自: https://www.includehelp.com/icp/letter-blog-writer-coding-problem-using-dynamic-programming.aspx

漢子編碼比字母編碼長

總結

以上是生活随笔為你收集整理的汉子编码比字母编码长_字母/博客作者编码问题(使用动态编程)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 一级成人av | 日批视屏| 日韩伦理视频 | 一本色道久久综合狠狠躁的推荐 | 国产二区三区视频 | 性按摩玩人妻hd中文字幕 | 大陆av在线 | 国产伦精品一区二区三区视频免费 | 最新日韩中文字幕 | 欧美成年人在线观看 | 中文字幕亚洲乱码熟女1区2区 | 午夜剧场成人 | 强行无套内谢大学生初次 | 特黄一级片| www四虎com | 91在线播 | 成人第一页| 俄罗斯女人裸体性做爰 | 亚洲精品乱码久久久久久日本蜜臀 | 国产经典毛片 | 二区视频在线观看 | 国产最爽的乱淫视频国语对白 | 女儿的朋友5中汉字晋通话 欧美成人免费高清视频 | xxx性欧美 | 国产精品骚 | 在线高清观看免费观看 | 午夜av免费看 | 国产精品美女www | 91丝袜呻吟高潮美腿白嫩 | 加勒比综合在线 | 欧美网站免费 | 欧美顶级少妇做爰 | 91国产视频在线播放 | 一区二区不卡视频在线观看 | 亚洲精华液一区二区 | 天天透天天操 | 特黄三级又爽又粗又大 | 先锋影音av在线 | 成人免费做受小说 | 无码人妻aⅴ一区二区三区玉蒲团 | 免费看国产片在线观看 | 久草综合视频 | 亚洲福利小视频 | 三年电影在线观看 | 欧美性生活免费视频 | 国产精品看片 | 亚洲射吧 | 国产www色| 亚洲在线视频观看 | 国产一区二区三区免费观看 | 91极品身材尤物theporn | 无码精品一区二区三区AV | 日本不卡视频在线播放 | 天堂中文在线最新 | 成人免费看片入口 | 精品成在人线av无码免费看 | 国产一级二级在线 | 国产露脸无套对白在线播放 | 国产91精品看黄网站在线观看 | 男女互操在线观看 | 熟女毛毛多熟妇人妻aⅴ在线毛片 | 成人va在线观看 | a极黄色片| 北条麻妃一区二区三区四区五区 | 日韩精品一卡二卡 | 日本黄色www | 久久久成人精品一区二区三区 | 欧美日韩一区二区三区四区五区六区 | 久久九九久精品国产免费直播 | jizz日韩 | 97人人在线视频 | 美女国产网站 | 久久理论电影 | av一级网站 | 医生强烈淫药h调教小说视频 | 一区二区视频在线免费观看 | 色噜噜一区二区 | 丁香花国语版普通话 | 国产亚洲精品久久久久丝瓜 | 国产亚洲成人av | 51吃瓜网今日吃瓜 | 国产精品久久久久久久久久直播 | 狠狠躁夜夜躁人人爽视频 | 秋霞视频一区二区 | 哺乳期喷奶水丰满少妇 | 激情全身裸吻胸 | 在线免费观看一区二区三区 | 亚洲小视频在线观看 | 日韩a视频 | 黄色片xxxx | 欧美三级又粗又硬 | 成人日韩欧美 | 涩色网站 | 91丝袜美女 | 在线视频这里只有精品 | 亚洲综合少妇 | 免费观看一区二区三区 | 欧美色悠悠 | 日本黄页网址 |