一道上海交大研究生入学考试试题:物以稀为贵

coding_leezam 2013-01-11 10:20:28
加精
1 2 3
4 5 6
7 8 9
0
说某移动电信运营商开发了一个名为“争霸”的游戏,为鼓励用户参与,凡签约用户均可获得前三位为888的手机号码,但这样的话就有10的8次方种可能,现在给出一种限制条件减少号码数量,就是两个相邻号码之间的关系必须满足象棋里的“将步”
即:给你前三位都是888 后面8位是上面的数字 每个数的相邻只有有限个数字
比如8881* 那么与1相邻的只可以是2和4
888812那么与2相邻的只可以是1,5,3 就是这个意思
如果选择5 那么可以选择的有2,4,6,8
问:
1 用什么算法比较好?为什么?
2 最优的算法是什么?为什么?
3 用什么数据结构最好?为什么?
4 时间复杂度和空间复杂度?
5 一共有多少种情况?

...全文
21930 155 打赏 收藏 转发到动态 举报
写回复
用AI写文章
155 条回复
切换为时间正序
请发表友善的回复…
发表回复
wo12l 2013-07-10
  • 打赏
  • 举报
回复
牛一点的初中生都会的DP
不会再变le 2013-06-08
  • 打赏
  • 举报
回复
引用 153 楼 a419635259 的回复:
我不多说,只写一个伪hash start->0,1,2,3,4,5,6,7,8,9 0->8 1->2,4 2->1,3,5 3->2,6 4->1,5,7 5->2,4,6,8 6->3,5,9 7->4,8 8->0,5,7,9 9->6,8 照此规则求一棵深度为8的树,一层一层的添加节点就行了,很简单的 然后从叶子节点访问到根就是一种情况 学完数据结构就能做了
10分钟想出来的。嘿嘿在读研究生
不会再变le 2013-06-08
  • 打赏
  • 举报
回复
我不多说,只写一个伪hash
start->0,1,2,3,4,5,6,7,8,9
0->8
1->2,4
2->1,3,5
3->2,6
4->1,5,7
5->2,4,6,8
6->3,5,9
7->4,8
8->0,5,7,9
9->6,8
照此规则求一棵深度为8的树,一层一层的添加节点就行了,很简单的

然后从叶子节点访问到根就是一种情况
学完数据结构就能做了
SharpUrMind 2013-04-11
  • 打赏
  • 举报
回复
Mark,有待研究
waldobear 2013-03-17
  • 打赏
  • 举报
回复
等俺能看懂了来研究研究。
wzb56 2013-03-17
  • 打赏
  • 举报
回复
longmenwaideyu 2013-03-17
  • 打赏
  • 举报
回复
状态压缩的动态规划吧。
asdjy123 2013-03-16
  • 打赏
  • 举报
回复
引用 81 楼 zhang_7150 的回复:
mark 等有功夫的时候研究下
+1
zxlmillie 2013-03-16
  • 打赏
  • 举报
回复
用大一的知识就能解决了,用一个数组就OK了!!! 后面的数字的个数为前面可能与这个数字相邻数字之和,代码如下: #include<iostream> using namespace std; const int Max=10; void PreSet(int Data[]); void Caculate(const int Data[],int New[]); void Assign(int Data[],int New[]); void Print(int New[]); int Count(int,const int Data[]); int main() { Instruction(); int Data[Max]; int New[Max]; PreSet(Data); for(int count=0;count<7;count++) { Caculate(Data,New); Assign(Data,New); } Print(New); return 0; } void PreSet(int Data[]) { for(int i=0;i<Max;i++) { Data[i]=1; } } void Assign(int Data[],int New[]) { for(int count=0;count<Max;count++) { Data[count]=New[count]; } } void Caculate(const int Data[],int New[]) { for(int j=0;j<Max;j++) { New[j]=Count(j,Data); } } int Count(int ele,const int Data[]) { switch(ele){ case 0:return Data[8]; case 1:return (Data[2]+Data[4]); case 2:return (Data[1]+Data[3]+Data[5]); case 3:return (Data[2]+Data[6]); case 4:return (Data[1]+Data[5]+Data[7]); case 5:return (Data[2]+Data[4]+Data[6]+Data[8]); case 6:return (Data[3]+Data[5]+Data[9]); case 7:return (Data[4]+Data[8]); case 8:return (Data[5]+Data[7]+Data[9]+Data[0]); case 9:return (Data[6]+Data[8]); } } void Print(int New[]) { int sum=0; for(int count=0;count<Max;count++) { sum+=New[count]; } cout<<"the result is"<<sum<<endl; }
  • 打赏
  • 举报
回复
现在的牛人多的无法无天.... 现在的牛人牛的无法无天....
雪舞飞影 2013-03-15
  • 打赏
  • 举报
回复
表示看到这题就有点蛋疼!!
Xuon 2013-03-15
  • 打赏
  • 举报
回复
怎么觉得有点像扫雷
linuxchyu 2013-03-14
  • 打赏
  • 举报
回复
一种比较SB的方法,耗时0.02s
#include <stdio.h>
int d[10]={1,1,1,1,1,1,1,1,1,1};


int calneibor(int i,int loop)
{
    if(loop == 1)
        switch (i)
        {
            case 0:return 1;
            case 1:return 2;
            case 2:return 3;
            case 3:return 2;
            case 4:return 3;
            case 5:return 4;
            case 6:return 3;
            case 7:return 2;
            case 8:return 4;
            case 9:return 2;
        }

    else {
        int next = loop-1;
        switch (i)
        {
            case 0:
                return calneibor(8,next);

            case 1:
                return calneibor(2,next)+calneibor(4,next);

            case 2:

                return calneibor(1,next)+calneibor(3,next)+calneibor(5,next);
            case 3:
                return calneibor(2,next)+calneibor(6,next);

            case 4:

                return calneibor(1,next)+calneibor(5,next)+calneibor(7,next);
            case 5:
                return calneibor(2,next)+calneibor(4,next)+calneibor(6,next)+calneibor(8,next);

            case 6:
                return calneibor(3,next)+calneibor(5,next)+calneibor(9,next);

            case 7:

                return calneibor(4,next)+calneibor(8,next);
            case 8:
                return calneibor(0,next)+calneibor(5,next)+calneibor(7,next)+calneibor(9,next);

            case 9:
                return calneibor(6,next)+calneibor(8,next);
        }
    }
}
int main()
{
    int sum  = 0;
    int i;
    for(i = 0;i<10;i++)
    {
        sum +=calneibor(i,7);
    }
    printf("total :%d",sum);
    return 0;
}
Onn0nnO 2013-03-13
  • 打赏
  • 举报
回复

		final int[][] map = { 
				{ 8 }, { 2, 4 }, { 1, 3, 5 }, { 2, 6 }, { 1, 5, 7 }, 
				{ 2, 4, 6, 8 }, { 3, 5, 9 }, { 4, 8 },
				{ 0, 5, 7, 9 }, { 6, 8 } };
		final int[][] res = new int[10][7];
		int sum = 0;

		for (int i = 0; i < 7; i++)
			for (int j = 0; j < 10; j++)
				if (i == 0)
					sum += res[j][i] = map[j].length;
				else {
					for (int n : map[j])
						res[j][i] += res[n][i - 1];
					sum += res[j][i];
				}
		System.out.println(sum);
meskin0556 2013-03-12
  • 打赏
  • 举报
回复
用心算 然后赋值 打印 哈哈 不过膜拜一下十三楼 不过如果不限定数字 可以将字母加进来的话 。。。。。。
coding_leezam 2013-03-12
  • 打赏
  • 举报
回复
引用 137 楼 F781492604 的回复:
我的解法: (defvar *an* '((8) (2 4) (1 3 5) (2 6) (1 5 7) (2 4 6 8) (3 5 9) (4 8) (0 5 7 9) (6 8))) (defvar *bn* '(1 1 1 1 1 1 1 1 1 1)) (defun sumnth (lst1 lst2) (apply #'+ (loop for i in lst1 coll……
顶啊~~~最近我也在学习LISP 计算机程序的构造与解释
F781492604 2013-03-12
  • 打赏
  • 举报
回复
lisp 果然很强大,10行就解决了
F781492604 2013-03-12
  • 打赏
  • 举报
回复
我的解法: (defvar *an* '((8) (2 4) (1 3 5) (2 6) (1 5 7) (2 4 6 8) (3 5 9) (4 8) (0 5 7 9) (6 8))) (defvar *bn* '(1 1 1 1 1 1 1 1 1 1)) (defun sumnth (lst1 lst2) (apply #'+ (loop for i in lst1 collect (nth i lst2)))) (defun sum-list (lst1 lst2) (loop for i in lst1 collect (sumnth i lst2))) (defun sumall (x lst) (if (eql x 1) lst (sumall (- x 1) (sum-list *an* lst)))) (apply #'+ (sumall 8 *bn*))
ben79802007 2013-03-11
  • 打赏
  • 举报
回复
总感觉各位的名字都叫“某天生”, 厉害啊
JSY_BJ 2013-03-11
  • 打赏
  • 举报
回复
我去,这太有压力了
加载更多回复(123)

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧