码迷,mamicode.com
首页 > 其他好文 > 详细

洛谷P1077 摆花 动态规划

时间:2017-05-22 13:24:17      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:man   nbsp   return   using   ret   algorithm   namespace   max   string   

洛谷P1077 摆花

DP   划分类动态规划  

 dp[ i ][ j ] 表示  到 第 i 种花,所有花总共取了 j 盆,总共的方案数 

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <cstdlib>
 5 #include <string>
 6 #include <algorithm>
 7 #include <iomanip>
 8 #include <iostream>
 9 using namespace std ;
10 
11 const int maxn = 101,maxm = 101,mod = 1000007 ;
12 int n,m ;
13 int a[maxn],dp[maxn][maxm] ;
14 
15 int main() 
16 {
17     scanf("%d%d",&n,&m) ;
18     for(int i=1;i<=n;i++) 
19         scanf("%d",&a[ i ]) ;
20     dp[ 0 ][ 0 ] = 1  ;
21     for(int i=1;i<=n;i++) 
22         for(int j=0;j<=m;j++)    
23             for(int k=0;k<=min( j,a[i] );k++ ) 
24              dp[i][j] = (dp[i][j] + dp[i-1][j-k]) % mod ; 
25     printf("%d\n",dp[n][m]) ;
26              
27             
28     return 0 ;
29 }

 

洛谷P1077 摆花 动态规划

标签:man   nbsp   return   using   ret   algorithm   namespace   max   string   

原文地址:http://www.cnblogs.com/third2333/p/6888695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!