is this correct?

is this soln correct for cutting rod problem

here v is length and m is total prices

if anyone can provide link for same type of problem so that i can submit it and check for correct answer

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
 {
	int t;
	cin>>t;
	while(t--)
	{
	    int v;
	    cin>>v;
	    int m;
	    cin>>m;
	    int p[m];
	    for(int i=0;i<m;i++)
	    {
	        cin>>p[i];
	    }
	    int dp[m+1][v+1];
	    for(int i=0;i<=m;i++)
	    {
	        for(int j=0;j<=v;j++)
	        {
	            if(i==0||j==0)
	            {
	                dp[i][j]=0;
	            }
	            else if(i<=j)
	            {
	                dp[i][j]=max(p[i-1]+dp[i][j-i],dp[i-1][j]);
	            }
	            else 
	            {
	                dp[i][j]=dp[i-1][j];
	            }
	        }
	    }
	    cout<<dp[m][v]<<endl;
	}
	return 0;
}