# sixth

long getsumcount(long data[], long count);

data[] = {1,2,3,4};
ncount = 4;

1  = 1
2  = 2
3  = 3 = 1+2
4  = 4 = 1+3

5  = 2+3 = 1+4
6  = 2+4 = 1+2+3
7  = 3+4 = 1+2+4
8  = 1+3+4
9  = 2+3+4
10 = 1+2+3+4

--

 第二题弄出来了，采用hash，在我4楼所说极端情况下，仍然是1.3G的CPU，使用时间1秒多。不过代码就长了点。#define hashsize (1<<16)#define hashmask (0xffff)typedef struct node{    long data;    struct node *next;}NODE;NODE hashtab[hashsize];/*寻找并插入，找到而未插入返回0，未找到而插入返回1*/static int hashinsert(long sum){    NODE *p,*q;    p = hashtab+ (sum & hashmask);    while( p && (p->data!=sum) )    {   q = p;        p = p->next;    }    if( p )        return 0;    q->next = p = malloc(sizeof(NODE));    p ->next = NULL;    p ->data = sum;    return 1;}/*删除hash表的第index条目*/static void hashdelete(long index){   NODE *p,*q;    p = hashtab[index].next;    while(p)    {   q = p;        p = p->next;        free(q);    }}/*这才是正主^^*/long getsumcount(long data[],long count){    long i;    int state[20] = {0};    long sum = 0,sp = 0;    int ret = 1; /*由于0已经先放入表中，所以首先就有一个*/        /*hash表初始化*/    for(i=0;i=0)    {   if(sp==count)        {   ret += hashinsert(sum);            --sp;        }        switch( state[sp] )        {   case 0:                state[sp] = 1;                sum += data[sp];                ++sp;                break;            case 1:                state[sp] = 2;                sum -= data[sp];                ++sp;                break;            case 2:                state[sp] = 0;                --sp;                break;        }    }    /*hash表销毁*/    for(i=0;i

--

• 本文已收录于以下专栏：

## 《黑马程序员》The sixth day

---------------------- android培训、java培训、期待与您交流！ ---------------------- ---------------------- an...

## C++ primer plus(sixth edition) 编程练习答案（answers for programing exercises）第八章(chapter 8) 1-4

8.1 #include void silly(const char * s, int n = 0); int main(void) { using namespace std; ...

## iOS-Best Practices for Interacting with a Remote Peripheral Device(API Reference) the sixth part

Best Practices for Interacting with a Remote Peripheral DeviceCore Bluetooth framework使许多central端交易简...

## sixth sense之用手势控制鼠标

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)