Travelling Salesman   After leaving Yemen, Bahosain now works as a salesman in Jordan. He spends most of his time travelling between different cities. He decided to buy a new car to help him in his job, but he has to decide about the capacity of the…
Rock-Paper-Scissors   Rock-Paper-Scissors is a two-player game, where each player chooses one of Rock, Paper, or Scissors. Here are the three cases in which a player gets one  point: ­          Choosing Rock wins over a player choosing  scissors. ­  …
Runtime Error   Bahosain was trying to solve this simple problem, but he got a Runtime Error on one of the test cases, can you help him by solving it? Given an array of N non-negative integers and an integer K, your task is to find two integers X and…
Heavy Coins   Bahosain has a lot of coins in his pocket. These coins are really heavy, so he always tries to get rid of some of the coins by using them when paying for the  taxi. Whenever Bahosain has to pay S pennies for the taxi driver, he tries to…
Epic Professor   Dr. Bahosain works as a professor of Computer Science at HU (Hadramout    University). After grading his programming exam, he noticed that most of the students have failed. Since this is the last semester for him teaching in Yemen, D…
Street Lamps   Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is a lamp in a block, it will light it’s block and the direct adjacent blocks. For example, if there is a lamp at block 3, it will light…
The "travelling salesman problem" asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?" It is an N…
题目链接:Travelling Salesman and Special Numbers 题意: 给出一个二进制数n,每次操作可以将这个数变为其二进制数位上所有1的和(3->2 ; 7->3),现在给出了一个数k,问不大于n的数中有几个数经过k次操作可以变成1. 题解: 因为所给的n很大,但是可以发现只要经过一次操作,n都会变成1000以内的数,所以可以把1000以内的数的答案都存下来.每次在这里面找等于k-1的数,然后数位DP求个数. #include<bits/stdc++.h>…
题目链接:Travelling Salesman and Special Numbers 题意: 给了一个n×m的图,图里面有'N','I','M','A'四种字符.问图中能构成NIMA这种序列最大个数(连续的,比如说NIMANIMA = 2)为多少,如果有环的话那么最大长度就是无穷. 题解: 哇,做了这题深深得感觉自己的dfs真的好弱.这题就是从N开始深搜,在深搜的过程中记录值.返回这个值加1. //#pragma comment(linker, "/stack:200000000"…
Travelling Salesman Problem Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5402 Mean: 现有一个n*m的迷宫,每一个格子都有一个非负整数,从迷宫的左上角(1,1)到迷宫的右下角(n,m),并且使得他走过的路径的整数之和最大,问最大和为多少以及他走的路径. analyse: 首先,因为每个格子都是非负整数,而且规定每个格子只能走一次,所以为了使和尽可能大,必定是走的格子数越多越好.这样我们就需…