uva1073 Glenbow Museum【解法一】
来源:互联网 发布:古代的美食 知乎 编辑:程序博客网 时间:2024/05/21 20:23
The famous Glenbow Museum in Calgary is Western Canada’s largest
museum, with exhibits ranging from art to cultural history to
mineralogy. A brand new section is being planned, devoted to brilliant
computer programmers just like you. Unfortunately, due to lack of
space, the museum is going to have to build a brand new building and
relocate into it. The size and capacity of the new building differ
from those of the original building. But the oor plans of both
buildings are orthogonal polygons. An orthogonal polygon is a polygon
whose internal angles are either 90 or 270. If 90 angles are denoted
as R (Right) and 270 angles are denoted as O (Ob- tuse) then a string
containing only R and O can roughly describe an orthogonal polygon.
For example, a rectangle (Figure 1) is the simplest orthogonal polygon
and it can be described as RRRR (the angles are listed in
counter-clockwise order, starting from any corner). Similarly, a
cross-shaped orthogonal polygon (Figure 2) can be described by the
sequence RRORRORRORRO, RORRORRORROR, or ORRORRORRORR. These sequences
are called angle strings . Of course, an angle string does not
completely specify the shape of a polygon | it says nothing about the
length of the sides. And some angle strings cannot possibly describe
a valid orthogonal polygon (RRROR, for example). To complicate things
further, not all orthogonal polygons are acceptable oor plans for the
mu- seum. A museum contains many valuable objects, and these objects
must be guarded. Due to cost considerations, no oor can have more
than one guard. So a oor plan is acceptable only if there is a place
within the oor from which one guard can see the entire oor.
Similarly, an angle string is acceptable only if it describes at least
one acceptable polygon. Note that the cross-shaped polygon in Figure 2
can be guarded by someone standing in the center, so it is acceptable.
Thus the angle string RRORRORRORRO is acceptable, even though it also
describes other polygons that cannot be properly guarded by a single
guard. Help the designers of the new building determine how many
acceptable angle strings there are of a given length. Input The input
le contains several test cases. Each test case consists of a line
containing a positive integer L (1 L 1000), which is the desired
length of an angle string. The input will end with a line containing
a single zero. Output For each test case, print a line containing the
test case number (beginning with 1) followed by the number of
acceptable angle strings of the given length. Follow the format of the
sample output.
解法二见【这里】。
根据多边形内角和,需要满足R有(n+4)/2个,O有(n-4)/2个,而存在一个监视点等价于没有两个连续的O。
用dp[i][j][k][l]表示前i位,R比O多j个,首尾分别是k和l的方案数,不难写出转移方程。
因为j的范围是[-1,5],所以复杂度是O(n)的。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longconst int c=3;int n;LL dp[1010][10][2][2];LL solve(){ int i,j; if ((n&1)||n<4) return 0; memset(dp,0,sizeof(dp)); dp[1][1+c][0][0]=dp[1][-1+c][1][1]=1; for (i=2;i<=n;i++) for (j=-1;j<=5;j++) { dp[i][j+c][0][0]=dp[i-1][j-1+c][0][0]+dp[i-1][j-1+c][0][1]; dp[i][j+c][0][1]=dp[i-1][j+1+c][0][0]; dp[i][j+c][1][0]=dp[i-1][j-1+c][1][0]+dp[i-1][j-1+c][1][1]; dp[i][j+c][1][1]=dp[i-1][j+1+c][1][0]; } return dp[n][4+c][0][0]+dp[n][4+c][0][1]+dp[n][4+c][1][0];}int main(){ int K=0; while (scanf("%d",&n)&&n) printf("Case %d: %lld\n",++K,solve());}
- uva1073 Glenbow Museum【解法一】
- uva1073 Glenbow Museum【解法二】
- uva1073 - Glenbow Museum
- Glenbow Museum LA4123
- UVALive - 4123 Glenbow Museum
- uvaoj 1073 - Glenbow Museum
- UVALive 4123Glenbow Museum
- uvala 4123 WF2008 Glenbow Museum
- uva 1073 - Glenbow Museum(递推)
- LA 4123 Glenbow Museum 葛伦堡博物馆
- LA 4123 Glenbow Museum (组合数)
- Uva 1073 - Glenbow Museum 解题报告(组合)
- UVA 1073 - Glenbow Museum(数论+计数问题+递推)
- uva live 4123 Glenbow Museum 数学递推
- ACM: uva 1073 - Glenbow Museum
- uva1073(数论)
- 求和问题解法一
- uva1262 Password【解法一】
- maven下载jar-source
- SQL Server 数据库性能优化
- 10.Facade-外观模式
- java编码规范
- 项目辅助工具类2
- uva1073 Glenbow Museum【解法一】
- fis3 前端项目构建,一步步来
- 算法篇---桶式排序和基数排序
- -[XXXX encodeWithCoder:]: unrecognized selector sent to instance 0x12d931d10
- django执行oracle sql报错ORA-00933: SQL command not properly ended
- unordered_map 与 map 的对比
- 自定义View
- iOS OAuth2使用
- 开发安卓Apps,我所努力学习到的三十多条宝贵经验