poj 1923 dp(Fourier's Lines)
2015-03-31 23:42
155 查看
题意:给定两个正整数n和m,问n条直线交于m个点最多能把平面分成多少部分。要求不会多于两条直线交于一点。
思路:dp。知道是dp可是自己还是在一个地方卡住了,忍不住搜了题解发现也比较好理解。
思路:dp。知道是dp可是自己还是在一个地方卡住了,忍不住搜了题解发现也比较好理解。
#include <cstdio> #include <cstring> int dp[105][10005]; int n,m,c=1; int out(int y,int x){ return y<0 || (y>x*(x-1)/2) || (y>0&&y<x-1); } int test(int x,int y){ int i; if(out(y,x)) return 0; if(!y) return 1; if(dp[x][y] != -1) return dp[x][y]; for(i = 1;i<=x;i++){ dp[x][y] = test(x-i, y-i*(x-i)); if(dp[x][y]) return 1; } return 0; } int main(){ memset(dp, -1, sizeof(dp)); while(scanf("%d %d",&n,&m) && (n+m)){ printf("Case %d: %d ",c++,n); if(test(n,m)) printf("lines with exactly %d crossings can cut the plane into %d pieces at most.\n",m,n+m+1); else printf("lines cannot make exactly %d crossings.\n",m); } return 0; }
相关文章推荐
- hdoj 1028/poj 2704 Pascal's Travels(记忆化搜索||dp)
- poj 2411 Mondriaan's Dream 状态压缩DP
- poj 2411 Mondriaan's Dream 【dp】
- poj 2411 Mondriaan's Dream(状态压缩+dp)
- pojPOJ 2411--Mondriaan's Dream+状态压缩dp
- HDOJ 1400 & POJ 2411 - Mondriaan's Dream 状态压缩DP
- poj2411 Mondriaan's Dream 插头dp做法
- poj 2411 Mondriaan's Dream(状压DP)
- POJ 1739 Tony's Tour (插头DP)
- POJ 2411 Mondriaan's Dream (状压DP)
- poj 2411 Mondriaan's Dream(状态压缩dp)
- poj 2411 Mondriaan's Dream_状态压缩dp
- poj 2411 && zoj 1100 Mondriaan's Dream ———状态压缩dp
- POJ 2411 Mondriaan's Dream 轮廓线DP
- POJ 2411 Mondriaan's Dream 状态压缩dp
- poj 2411 Mondriaan's Dream(状态压缩DP)
- POJ 2411 Mondriaan's Dream(铺装问题) 状态DP
- POJ-2411 Mondriaan's Dream 状态压缩DP
- poj 2411 Mondriaan's Dream 状压dp入门
- poj 1739 Tony's Tour(插头dp)