HDU 1723-Distribute Message-dp-(有向图路径模型)

题意:一队人传递消息,一个人可以向后传给m个人,求最后一个人得到消息的方式有多少种。有向图求起点到终点有多少条路径模型。

分析:dp[i]表示第i个人得到消息的方式有dp[i]种,dp[i]=dp[i-1]+.....+dp[i-m]。求方式的状态转移方程基本上都是这个样子。

代码:

#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int dp[100];
void DP()
{
	memset(dp,0,sizeof(dp));
	dp[1]=1;
	for(int i=2;i<=n;i++){
		for(int j=i-1;i-j<=m&&j>0;j--)
		   dp[i]+=dp[j];
	}
}
int main()
{
    while(cin>>n>>m){
    	if(!n&&!m) break;
    	DP();
    	cout<<dp[n]<<endl;
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-24 11:13:41

HDU 1723-Distribute Message-dp-(有向图路径模型)的相关文章

HDU 1723 Distribute Message DP

The contest’s message distribution is a big thing in prepare. Assuming N students stand in a row, from the row-head start transmit message, each person can transmit message to behind M personals, and how many ways could row-tail get the message? Inpu

hdu 1723 Distribute Message 递推

#include <cstdio> #include <cstring> using namespace std; int dp[50]; int main() { int n,m; while(1) { scanf("%d%d",&n,&m); if(n==0&&m==0) break; int i,j; memset(dp,0,sizeof(dp)); dp[1]=1; for(i=2;i<=n;i++) for(j=i

hdu 5092 Seam Carving dp+记录路径

Seam Carving Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 605    Accepted Submission(s): 253 Problem Description Fish likes to take photo with his friends. Several days ago, he found that so

DP HDU 1723

简单的DP Distribute Message Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1345    Accepted Submission(s): 625 Problem Description The contest's message distribution is a big thing in prepare. As

hdu 4862 KM算法 最小K路径覆盖的模型

http://acm.hdu.edu.cn/showproblem.php?pid=4862 选t<=k次,t条路要经过所有的点一次并且仅仅一次, 建图是问题: 我自己最初就把n*m 个点分别放入X集合以及Y集合,再求最优匹配,然后连样例都过不了,而且其实当时解释不了什么情况下不能得到结果,因为k此这个条件相当于没用上... 建图方法: 1.X集合和Y集合都放入n*m+k个点,X中前n*m个点和Y中前n*m个点之间,如果格子里的值相等,权就是(收益-耗费),不等就是(-耗费),因为要的是最大收益

HDU 4960 (水dp)

Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xi

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

hdu 2296 aC自动机+dp(得到价值最大的字符串)

Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3180    Accepted Submission(s): 1033 Problem Description For the hope of a forever love, Steven is planning to send a ring to Jane with a rom

hdu 2457 AC自动机+dp

DNA repair Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2004    Accepted Submission(s): 1085 Problem Description Biologists finally invent techniques of repairing DNA that contains segments c