Problem Description: Banana leaf platter is a traditional method of serving rice dishes in South Indian cuisine. Due to the migration of South Indians, banana leaf rice can also be found in areas with significant ethnic South Indian diaspora such as Malaysia and Singapore. Irfan is a banana leaf sales person. he has N stacks of banana leafs. Each stack contains K leafs. Each leaf has a positive beauty value, describing how attractive it looks. Irfan would like to take exactly P leafs to use for lunch today. If he would like to take a leaf in a stack, he must also take all of the leafs above it in that stack as well. Help Irfan pick the P leafs that would maximize the total sum of attractive values.
C Program

#include<stdio.h>

int max(int a,int b)
{
    return (a>b)?a:b;
}

int main()
{
    int T;
    scanf("%d",&T);

    while(T--)
    {
        int n,k,p;
        scanf("%d %d %d",&n,&k,&p);

        int a[55][35], prefix[55][35]={0};

        // Input + prefix sum
        for(int i = 0;i < n;i++)
        {
            for(int j=1;j<=k;j++)
            {
                scanf("%d",&a[i][j]);
                prefix[i][j] = prefix[i][j-1] + a[i][j];
            }
        }

        int dp[55][1505]={0};

        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=p;j++)
            {
                for(int x=0;x<=j && x<=k;x++)
                {
                    dp[i][j] = max(dp[i][j],
                                   dp[i-1][j-x] + prefix[i-1][x]);
                }
            }
        }

        printf("%d\n",dp[n][p]);
    }

    return 0;
}