FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp/algorithms/dynamic-programming/rod_cutting.cpp at master · AllAlgorithms/cpp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
AllAlgorithms
/
cpp
Public archive
Notifications
You must be signed in to change notification settings
Fork
339
Star
841
Code
Issues
9
Pull requests
33
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp
/
algorithms
/
dynamic-programming
/
rod_cutting.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (32 loc) · 728 Bytes
Breadcrumbs
cpp
/
algorithms
/
dynamic-programming
/
rod_cutting.cpp
Copy path
File metadata and controls
46 lines (32 loc) · 728 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
include
<
iostream
>
#
include
<
climits
>
using
namespace
std
;
int
rodCutting
(
int
n,
int
value[])
{
int
i,j;
int
result[n+
1
];
result[
0
]=
0
;
for
(i=
1
;i<=n;i++)
{
result[i]=
INT_MIN
;
for
(j=
0
;j<i;j++)
{
result[i]=
max
(result[i],value[j]+result[i-(j+
1
)]);
}
}
return
result[n];
}
int
main
()
{
int
n;
cout<<
"
Enter the length of the rod
"
<<endl;
cin>>n;
int
value[n];
cout<<
"
Enter the values of pieces of rod of all size
"
<<endl;
for
(
int
i=
0
;i<n;i++)
cin>>value[i];
cout<<
"
Maximum obtainable value by cutting up the rod in many pieces are
"
<<endl;
cout<<
rodCutting
(n,value);
cout<<endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL